From 52e1267d4a01c23268e618992e6b76b773d074c0 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 22 Jul 2003 22:32:40 +0000 Subject: [PATCH] Create a special type of ICDIVariable (ErrorVariable) if request to gdb fails. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 5 + .../cdt/debug/internal/core/model/CValue.java | 32 +++-- .../debug/internal/core/model/CVariable.java | 121 +++++++++++++++++- 3 files changed, 143 insertions(+), 15 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 65f7e7a437d..ca0c65b5b59 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,8 @@ +2003-07-22 Mikhail Khodjaiants + Create a special type of ICDIVariable (ErrorVariable) if request to gdb fails. + * CVariable.java + * CValue.java + 2003-07-22 Mikhail Khodjaiants Use the 'getReferencedProjects' method of 'CSourceLocator' to obtain the list of referenced projects. Use the correct tag for additional source locations. 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 fbd43146bed..b6b456a8bb8 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 @@ -27,6 +27,7 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue; +import org.eclipse.cdt.debug.core.model.ICDebugElementErrorStatus; import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator; import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.debug.core.DebugException; @@ -133,19 +134,29 @@ public class CValue extends CDebugElement implements ICValue return Collections.EMPTY_LIST; if ( fVariables.size() == 0 ) { - List vars = getCDIVariables(); - - if ( vars.size() > 1 ) - fVariables = CArrayPartition.splitArray( this, vars, 0, vars.size() - 1 ); - else + try { - fVariables = new ArrayList( vars.size() ); - Iterator it = vars.iterator(); - while( it.hasNext() ) + List vars = getCDIVariables(); + + if ( vars.size() > 1 ) + fVariables = CArrayPartition.splitArray( this, vars, 0, vars.size() - 1 ); + else { - fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) ); + fVariables = new ArrayList( vars.size() ); + Iterator it = vars.iterator(); + while( it.hasNext() ) + { + fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) ); + } } } + catch( DebugException e ) + { + fVariables = new ArrayList( 1 ); + CModificationVariable var = new CModificationVariable( this, new CVariable.ErrorVariable( null, e ) ); + var.setStatus( ICDebugElementErrorStatus.ERROR, e.getMessage() ); + fVariables.add( var ); + } } return fVariables; } @@ -192,8 +203,7 @@ public class CValue extends CDebugElement implements ICValue } catch( CDIException e ) { - vars = new ICDIVariable[0]; - infoMessage( e ); + requestFailed( "not available: ", e ); } return Arrays.asList( vars ); } 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 7d11a1806f2..e7735a3e047 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 @@ -5,6 +5,7 @@ */ package org.eclipse.cdt.debug.internal.core.model; +import java.text.MessageFormat; import java.util.LinkedList; import org.eclipse.cdt.debug.core.CDebugCorePlugin; @@ -19,9 +20,12 @@ import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; 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.core.cdi.model.ICDIVariable; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; +import org.eclipse.cdt.debug.core.model.ICDebugElementErrorStatus; import org.eclipse.cdt.debug.core.model.ICType; import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICVariable; @@ -47,6 +51,106 @@ public abstract class CVariable extends CDebugElement ICastToType, ICastToArray { + /** + * The instance of this class is created when the 'getCDIVariable' call throws an exception. + * + * @since Jul 22, 2003 + */ + public static class ErrorVariable implements ICDIVariable + { + private ICDIVariableObject fVariableObject; + private Exception fException; + + public ErrorVariable( ICDIVariableObject varObject, Exception e ) + { + fVariableObject = varObject; + fException = e; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getStackFrame() + */ + public ICDIStackFrame getStackFrame() throws CDIException + { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getName() + */ + public String getName() + { + return ( fVariableObject != null ) ? fVariableObject.getName() : ""; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getTypeName() + */ + public String getTypeName() throws CDIException + { + // TODO When the 'getType' method is moved to 'ICDIVariableObject' + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getType() + */ + public ICDIType getType() throws CDIException + { + // TODO When the 'getType' method is moved to 'ICDIVariableObject' + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue() + */ + public ICDIValue getValue() throws CDIException + { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#isEditable() + */ + public boolean isEditable() throws CDIException + { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(java.lang.String) + */ + public void setValue( String expression ) throws CDIException + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(org.eclipse.cdt.debug.core.cdi.model.ICDIValue) + */ + public void setValue( ICDIValue value ) throws CDIException + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setFormat(int) + */ + public void setFormat( int format ) throws CDIException + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIObject#getTarget() + */ + public ICDITarget getTarget() + { + return ( fVariableObject != null ) ? fVariableObject.getTarget() : null; + } + + public Exception getException() + { + return fException; + } + } class InternalVariable { private ICDIVariableObject fCDIVariableObject; @@ -67,10 +171,19 @@ public abstract class CVariable extends CDebugElement { if ( fCDIVariable == null ) { - if ( getCDIVariableObject() instanceof ICDIArgumentObject ) - fCDIVariable = getCDISession().getVariableManager().createArgument( (ICDIArgumentObject)getCDIVariableObject() ); - else if ( getCDIVariableObject() instanceof ICDIVariableObject ) - fCDIVariable = getCDISession().getVariableManager().createVariable( getCDIVariableObject() ); + try + { + if ( getCDIVariableObject() instanceof ICDIArgumentObject ) + fCDIVariable = getCDISession().getVariableManager().createArgument( (ICDIArgumentObject)getCDIVariableObject() ); + else if ( getCDIVariableObject() instanceof ICDIVariableObject ) + fCDIVariable = getCDISession().getVariableManager().createVariable( getCDIVariableObject() ); + } + catch( CDIException e ) + { + fCDIVariable = new ErrorVariable( getCDIVariableObject(), e ); + setStatus( ICDebugElementErrorStatus.ERROR, + MessageFormat.format( "not available: {0}", new String[] { e.getMessage() } ) ); + } } return fCDIVariable; }