From a9605d9359a014b5ab1a236023b90ce9c2b959bf Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Mon, 25 Sep 2006 22:38:40 +0000 Subject: [PATCH] Bug 150565. Expressions cache their variable objects so they don't ask gdb to create a new one each time the expression value is determined. --- .../debug/mi/core/cdi/model/Expression.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Expression.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Expression.java index e8eab22252d..8a0df26e4b8 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Expression.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Expression.java @@ -30,6 +30,8 @@ public class Expression extends CObject implements ICDIExpression { private int id; String fExpression; Type fType; + Variable fVariable; + ICDIStackFrame fContext; public Expression(Target target, String ex) { super(target); @@ -96,8 +98,19 @@ public class Expression extends CObject implements ICDIExpression { public ICDIValue getValue(ICDIStackFrame context) throws CDIException { Session session = (Session)getTarget().getSession(); ExpressionManager mgr = session.getExpressionManager(); - Variable var = mgr.createVariable((StackFrame)context, getExpressionText()); - return var.getValue(); + if (fVariable != null && fContext != null && !context.equals(fContext)) + { // Get rid of the underlying variable if the context has changed. + // This is defensive, in practice each stack frame has it's own + // list of expressions. + mgr.deleteVariable(fVariable); + fVariable = null; + } + if (fVariable == null) + { // Reuse the variable so we don't have to ask gdb to create another one. Bug 150565. + fVariable = mgr.createVariable((StackFrame)context, getExpressionText()); + } + fContext = context; + return fVariable.getValue(); } /* (non-Javadoc) @@ -107,6 +120,8 @@ public class Expression extends CObject implements ICDIExpression { Session session = (Session)getTarget().getSession(); ExpressionManager mgr = session.getExpressionManager(); mgr.destroyExpressions((Target)getTarget(), new Expression[] {this}); + if (fVariable != null) + mgr.deleteVariable(fVariable); } }