From 1c05c517d039842b343004ffe8bceb4adcc93b6c Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 25 Oct 2004 04:21:21 +0000 Subject: [PATCH] 2004-10-25 Alain Magloire Remove of ICDExpressionManager in CDI ICDIExpression changes in the interface. * cdi/rg/eclipse/cdt/debug/mo/core/cdi/EventManager.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/ExpressionManager.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/Session.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/event/ChangedEvent.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/event/DestroyedEvent.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Expression.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Target.java * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Variable.java --- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 12 + .../cdt/debug/mi/core/cdi/EventManager.java | 2 +- .../debug/mi/core/cdi/ExpressionManager.java | 233 +++++------------- .../cdt/debug/mi/core/cdi/Session.java | 5 +- .../debug/mi/core/cdi/event/ChangedEvent.java | 2 +- .../mi/core/cdi/event/DestroyedEvent.java | 11 +- .../debug/mi/core/cdi/model/Expression.java | 120 ++++++++- .../cdt/debug/mi/core/cdi/model/Target.java | 45 +++- .../cdt/debug/mi/core/cdi/model/Variable.java | 17 +- 9 files changed, 239 insertions(+), 208 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index f50fba6c130..96a6c0ac53a 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,15 @@ +2004-10-25 Alain Magloire + Remove of ICDExpressionManager in CDI + ICDIExpression changes in the interface. + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/EventManager.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/ExpressionManager.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/Session.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/event/ChangedEvent.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/event/DestroyedEvent.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Expression.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Target.java + * cdi/rg/eclipse/cdt/debug/mo/core/cdi/model/Variable.java + 2004-10-24 Alain Magloire Changes in ICDITarget.evaluateExpressionToString() * org/eclipse/cdt/debug/mi/core/cdi/model/Target.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java index 9f7ab27f563..a09cc0e70d8 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java @@ -299,7 +299,7 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs // Update the managers. // For the Variable/Expression Managers call only the updateManager. VariableManager varMgr = (VariableManager)session.getVariableManager(); - ExpressionManager expMgr = (ExpressionManager)session.getExpressionManager(); + ExpressionManager expMgr = session.getExpressionManager(); RegisterManager regMgr = (RegisterManager)session.getRegisterManager(); MemoryManager memMgr = (MemoryManager)session.getMemoryManager(); BreakpointManager bpMgr = session.getBreakpointManager(); diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java index 206d58fee32..7f53f743920 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java @@ -11,39 +11,29 @@ package org.eclipse.cdt.debug.mi.core.cdi; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Hashtable; import java.util.List; import java.util.Map; import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; -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.ICDIThread; 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.Expression; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; -import org.eclipse.cdt.debug.mi.core.cdi.model.VariableObject; 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.command.MIVarDelete; import org.eclipse.cdt.debug.mi.core.command.MIVarUpdate; import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MIVarChangedEvent; import org.eclipse.cdt.debug.mi.core.event.MIVarDeletedEvent; -import org.eclipse.cdt.debug.mi.core.output.MIVar; import org.eclipse.cdt.debug.mi.core.output.MIVarChange; -import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo; import org.eclipse.cdt.debug.mi.core.output.MIVarUpdateInfo; /** */ -public class ExpressionManager extends Manager implements ICDIExpressionManager{ +public class ExpressionManager extends Manager { final static ICDIExpression[] EMPTY_EXPRESSIONS = {}; Map expMap; @@ -62,132 +52,17 @@ public class ExpressionManager extends Manager implements ICDIExpressionManager{ } return expList; } - /** - * Tell gdb to remove the underlying var-object also. - */ - void removeMIVar(MISession miSession, MIVar miVar) throws CDIException { - CommandFactory factory = miSession.getCommandFactory(); - MIVarDelete var = factory.createMIVarDelete(miVar.getVarName()); - try { - miSession.postCommand(var); - var.getMIInfo(); - } catch (MIException e) { - throw new MI2CDIException(e); - } - } /** - * When element are remove from the cache, - * The destroy event will call removeExpression. - */ - public void removeExpression(MISession miSession, String varName) throws CDIException { - Target target = ((Session)getSession()).getTarget(miSession); - List expList = (List)expMap.get(target); - if (expList != null) { - Expression[] exps = (Expression[]) expList.toArray(new Expression[expList.size()]); - for (int i = 0; i < exps.length; i++) { - if (exps[i].getMIVar().getVarName().equals(varName)) { - expList.remove(exps[i]); - removeMIVar(miSession, exps[i].getMIVar()); - } - } - } - } - - /** - * This should bo remove to evaluate an expression we nee a context. - * - * @deprecated - * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(String) - */ - public ICDIExpression createExpression(String name) throws CDIException { - Target target = ((Session)getSession()).getCurrentTarget(); - return createExpression(target, name); - } - /** - * This should bo remove to evaluate an expression we nee a context. - * - * @deprecated * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(String) */ public ICDIExpression createExpression(Target target, String name) throws CDIException { - Expression expression = null; - Session session = (Session)getSession(); - Target currentTarget = session.getCurrentTarget(); - session.setCurrentTarget(target); - try { - MISession mi = target.getMISession(); - CommandFactory factory = mi.getCommandFactory(); - MIVarCreate var = factory.createMIVarCreate(name); - mi.postCommand(var); - MIVarCreateInfo info = var.getMIVarCreateInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ - } - VariableObject varObj = new VariableObject(target, name, null, 0, 0); - expression = new Expression(varObj, info.getMIVar()); - List expList = getExpressionList(target); - expList.add(expression); - } catch (MIException e) { - throw new MI2CDIException(e); - } finally { - session.setCurrentTarget(currentTarget); - } + Expression expression = new Expression(target, name); + List exprList = getExpressionList(target); + exprList.add(expression); return expression; } - /** - * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(ICDIStackFrame, String) - */ - public ICDIExpression createExpression(ICDIStackFrame frame, String name) throws CDIException { - Expression expression = null; - Session session = (Session)getSession(); - Target currentTarget = session.getCurrentTarget(); - ICDIThread currentThread = currentTarget.getCurrentThread(); - ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame(); - Target target = (Target)frame.getTarget(); - session.setCurrentTarget(target); - target.setCurrentThread(frame.getThread(), false); - frame.getThread().setCurrentStackFrame(frame, false); - try { - MISession mi = target.getMISession(); - CommandFactory factory = mi.getCommandFactory(); - MIVarCreate var = factory.createMIVarCreate(name); - mi.postCommand(var); - MIVarCreateInfo info = var.getMIVarCreateInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ - } - VariableObject varObj = new VariableObject(target, name, frame, 0, 0); - expression = new Expression(varObj, info.getMIVar()); - List expList = getExpressionList(target); - expList.add(expression); - } catch (MIException e) { - throw new MI2CDIException(e); - } finally { - session.setCurrentTarget(currentTarget); - target.setCurrentThread(currentThread, false); - currentThread.setCurrentStackFrame(currentFrame, false); - } - return expression; - } - - /** - * @deprecated - * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getExpressions() - */ - public ICDIExpression[] getExpressions() throws CDIException { - ICDITarget[] targets = getSession().getTargets(); - List list = new ArrayList(targets.length); - for (int i = 0; i < targets.length; i++) { - if (targets[i] instanceof Target) { - ICDIExpression[] exprs = getExpressions((Target)targets[i]); - list.addAll(Arrays.asList(exprs)); - } - } - return (ICDIExpression[]) list.toArray(new ICDIExpression[list.size()]); - } - public ICDIExpression[] getExpressions(Target target) throws CDIException { List expList = (List) expMap.get(target); if (expList != null) { @@ -195,40 +70,26 @@ public class ExpressionManager extends Manager implements ICDIExpressionManager{ } return EMPTY_EXPRESSIONS; } + /** * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression) */ - public void destroyExpression(ICDIExpression expression) throws CDIException { - if (expression instanceof Expression) { - // Fire a destroyEvent ? - Expression exp= (Expression)expression; - Target target = (Target)exp.getTarget(); - MISession miSession = target.getMISession(); - MIVarDeletedEvent del = new MIVarDeletedEvent(miSession, exp.getMIVar().getVarName()); - miSession.fireEvent(del); + public void destroyExpressions(Target target, ICDIExpression[] expressions) throws CDIException { + List expList = getExpressionList(target); + for (int i = 0; i < expressions.length; ++i) { + if (expressions[i] instanceof Expression) { + expList.remove(expressions[i]); + ((Expression)expressions[i]).deleteVariable(); + } } } /** - * Return the element that have the uniq varName. - * null is return if the element is not in the cache. + * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression) */ - public Variable getExpression(MISession miSession, String varName) { - Target target = ((Session)getSession()).getTarget(miSession); - List expList = (List)expMap.get(target); - if (expList != null) { - Expression[] exps = (Expression[]) expList.toArray(new Expression[expList.size()]); - for (int i = 0; i < exps.length; i++) { - if (exps[i].getMIVar().getVarName().equals(varName)) { - return exps[i]; - } - Variable v = exps[i].getChild(varName); - if (v != null) { - return v; - } - } - } - return null; + public void destroyAllExpressions(Target target) throws CDIException { + ICDIExpression[] expressions = getExpressions(target); + destroyExpressions(target, expressions); } public void update(Target target) throws CDIException { @@ -238,33 +99,53 @@ public class ExpressionManager extends Manager implements ICDIExpressionManager{ List expList = getExpressionList(target); Expression[] exps = (Expression[])expList.toArray(new Expression[0]); for (int i = 0; i < exps.length; i++) { - String varName = exps[i].getMIVar().getVarName(); - MIVarChange[] changes = noChanges; - MIVarUpdate update = factory.createMIVarUpdate(varName); - try { - mi.postCommand(update); - MIVarUpdateInfo info = update.getMIVarUpdateInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + Variable variable = exps[i].getVariable(); + if (variable != null) { + String varName = variable.getMIVar().getVarName(); + MIVarChange[] changes = noChanges; + MIVarUpdate update = factory.createMIVarUpdate(varName); + try { + mi.postCommand(update); + MIVarUpdateInfo info = update.getMIVarUpdateInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + changes = info.getMIVarChanges(); + } catch (MIException e) { + //throw new MI2CDIException(e); + eventList.add(new MIVarDeletedEvent(mi, varName)); } - changes = info.getMIVarChanges(); - } catch (MIException e) { - //throw new MI2CDIException(e); - eventList.add(new MIVarDeletedEvent(mi, varName)); - } - for (int j = 0 ; j < changes.length; j++) { - String n = changes[j].getVarName(); - if (changes[j].isInScope()) { - eventList.add(new MIVarChangedEvent(mi, n)); + for (int j = 0 ; j < changes.length; j++) { + String n = changes[j].getVarName(); + if (changes[j].isInScope()) { + eventList.add(new MIVarChangedEvent(mi, n)); + } } - // We do not implicitely delete Expressions. - //else { - // eventList.add(new MIVarDeletedEvent(n)); - //} } } MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]); mi.fireEvents(events); } + /** + * @param miSession + * @param varName + * @return + */ + public Expression getExpression(MISession miSession, String varName) { + Session session = (Session)getSession(); + Target target = session.getTarget(miSession); + List expList = getExpressionList(target); + Expression[] exps = (Expression[])expList.toArray(new Expression[0]); + for (int i = 0; i < exps.length; i++) { + Variable variable = exps[i].getVariable(); + if (variable != null) { + if (variable.getMIVar().getVarName().equals(varName)) { + return exps[i]; + } + } + } + return null; + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java index 70c7f7ee3bc..d0cc5c671e4 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/Session.java @@ -16,7 +16,6 @@ import java.util.Properties; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDIEventManager; -import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager; import org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager; import org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -137,7 +136,7 @@ public class Session implements ICDISession, ICDISessionObject { /** * @see org.eclipse.cdt.debug.core.cdi.ICDISession#getExpressionManager() */ - public ICDIExpressionManager getExpressionManager() { + public ExpressionManager getExpressionManager() { return expressionManager; } @@ -196,7 +195,7 @@ public class Session implements ICDISession, ICDISessionObject { */ public void setCurrentTarget(Target target) throws CDIException { ProcessManager pMgr = getProcessManager(); - pMgr.setCurrentTarget((Target)target); + pMgr.setCurrentTarget(target); // throw new CDIException(CdiResources.getString("cdi.Session.Unknown_target")); //$NON-NLS-1$ } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ChangedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ChangedEvent.java index 1c93eae0ea9..b399bb81525 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ChangedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/ChangedEvent.java @@ -49,7 +49,7 @@ public class ChangedEvent implements ICDIChangedEvent { // Try the Expression manager if (source == null) { - ExpressionManager expMgr = (ExpressionManager)session.getExpressionManager(); + ExpressionManager expMgr = session.getExpressionManager(); source = expMgr.getExpression(miSession, varName); } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/DestroyedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/DestroyedEvent.java index 77bd1a8b0f4..8f231fcef74 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/DestroyedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/DestroyedEvent.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager; import org.eclipse.cdt.debug.mi.core.cdi.VariableManager; import org.eclipse.cdt.debug.mi.core.cdi.model.Breakpoint; import org.eclipse.cdt.debug.mi.core.cdi.model.CObject; +import org.eclipse.cdt.debug.mi.core.cdi.model.Expression; 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; @@ -56,12 +57,12 @@ public class DestroyedEvent implements ICDIDestroyedEvent { } catch (CDIException e) { } } else { - ExpressionManager expMgr = (ExpressionManager)session.getExpressionManager(); - variable = expMgr.getExpression(miSession, varName); - if (variable != null) { - source = variable; + ExpressionManager expMgr = session.getExpressionManager(); + Expression expression = expMgr.getExpression(miSession, varName); + if (expression != null) { + source = expression; try { - expMgr.removeExpression(miSession, variable.getMIVar().getVarName()); + expression.deleteVariable(); } catch (CDIException e) { } } else { 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 5d9b79fd17d..375e57b5a39 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 @@ -10,14 +10,128 @@ *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.cdi.model; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; +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.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.MI2CDIException; +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.command.MIVarDelete; import org.eclipse.cdt.debug.mi.core.output.MIVar; +import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo; + /** */ -public class Expression extends Variable implements ICDIExpression { +public class Expression extends CObject implements ICDIExpression { - public Expression(VariableObject obj, MIVar var) { - super(obj, var); + private static int ID_COUNT = 0; + private int id; + String fExpression; + Variable fVariable; + + public Expression(Target target, String ex) { + super(target); + fExpression = ex; + id = ++ID_COUNT; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#getExpressionText() + */ + public String getExpressionText() { + return fExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#equals(org.eclipse.cdt.debug.core.cdi.model.ICDIExpression) + */ + public boolean equals(ICDIExpression obj) { + if (obj instanceof Expression) { + Expression other = (Expression)obj; + return other.id == id; + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#getValue(org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame) + */ + public ICDIValue getValue(ICDIStackFrame context) throws CDIException { + if (fVariable != null) { + Target target = (Target)getTarget(); + MISession miSession = target.getMISession(); + removeMIVar(miSession, fVariable.getMIVar()); + } + fVariable = createVariable(context); + return fVariable.getValue(); + } + + public Variable getVariable() { + return fVariable; + } + + protected Variable createVariable(ICDIStackFrame frame) throws CDIException { + Session session = (Session)getTarget().getSession(); + Target currentTarget = session.getCurrentTarget(); + ICDIThread currentThread = currentTarget.getCurrentThread(); + ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame(); + Target target = (Target)frame.getTarget(); + session.setCurrentTarget(target); + target.setCurrentThread(frame.getThread(), false); + frame.getThread().setCurrentStackFrame(frame, false); + try { + MISession mi = target.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIVarCreate var = factory.createMIVarCreate(fExpression); + mi.postCommand(var); + MIVarCreateInfo info = var.getMIVarCreateInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + VariableObject varObj = new VariableObject(target, fExpression, frame, 0, 0); + return new Variable(varObj, info.getMIVar()); + } catch (MIException e) { + throw new MI2CDIException(e); + } finally { + session.setCurrentTarget(currentTarget); + target.setCurrentThread(currentThread, false); + currentThread.setCurrentStackFrame(currentFrame, false); + } + } + + /** + * Get rid of the underlying variable. + * + */ + public void deleteVariable() throws CDIException { + if (fVariable != null) { + Target target = (Target)getTarget(); + MISession miSession = target.getMISession(); + MIVar miVar = fVariable.getMIVar(); + removeMIVar(miSession, fVariable.getMIVar()); + fVariable = null; + } + } + + /** + * Tell gdb to remove the underlying var-object also. + */ + public void removeMIVar(MISession miSession, MIVar miVar) throws CDIException { + CommandFactory factory = miSession.getCommandFactory(); + MIVarDelete var = factory.createMIVarDelete(miVar.getVarName()); + try { + miSession.postCommand(var); + var.getMIInfo(); + } catch (MIException e) { + throw new MI2CDIException(e); + } + } + } 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 58cd73701ae..f470fceab61 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 @@ -19,6 +19,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDICondition; import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; +import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; import org.eclipse.cdt.debug.core.cdi.model.ICDILocationBreakpoint; import org.eclipse.cdt.debug.core.cdi.model.ICDIRuntimeOptions; import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; @@ -31,6 +32,7 @@ import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MISession; import org.eclipse.cdt.debug.mi.core.cdi.BreakpointManager; 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; @@ -625,17 +627,6 @@ public class Target implements ICDITarget { } } - /** - * @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#evaluateExpressionToString(String) - */ - public String evaluateExpressionToString(String expressionText) throws CDIException { - Session session = (Session)getSession(); - Target currentTarget = session.getCurrentTarget(); - ICDIThread currentThread = currentTarget.getCurrentThread(); - ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame(); - return evaluateExpressionToString(currentFrame, expressionText); - } - public String evaluateExpressionToString(ICDIStackFrame frame, String expressionText) throws CDIException { Session session = (Session)getSession(); Target currentTarget = session.getCurrentTarget(); @@ -783,4 +774,36 @@ public class Target implements ICDITarget { public ICDIRuntimeOptions getRuntimeOptions() { return new RuntimeOptions(this); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpressionManagement#createExpression(java.lang.String) + */ + public ICDIExpression createExpression(String code) throws CDIException { + ExpressionManager expMgr = ((Session)getSession()).getExpressionManager(); + return expMgr.createExpression(this, code); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpressionManagement#getExpressions() + */ + public ICDIExpression[] getExpressions() throws CDIException { + ExpressionManager expMgr = ((Session)getSession()).getExpressionManager(); + return expMgr.getExpressions(this); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpressionManagement#destroyExpression(org.eclipse.cdt.debug.core.cdi.model.ICDIExpression[]) + */ + public void destroyExpressions(ICDIExpression[] expressions) throws CDIException { + ExpressionManager expMgr = ((Session)getSession()).getExpressionManager(); + expMgr.destroyExpressions(this, expressions); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpressionManagement#destroyAllExpression() + */ + public void destroyAllExpressions() throws CDIException { + ExpressionManager expMgr = ((Session)getSession()).getExpressionManager(); + expMgr.destroyAllExpressions(this); + } } 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 d764d431f10..191fd3c90f7 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 @@ -37,6 +37,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.ExpressionManager; import org.eclipse.cdt.debug.mi.core.cdi.Format; 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.cdi.VariableManager; import org.eclipse.cdt.debug.mi.core.cdi.model.type.ArrayValue; import org.eclipse.cdt.debug.mi.core.cdi.model.type.BoolValue; @@ -320,18 +321,18 @@ public class Variable extends VariableObject implements ICDIVariable { if (mgr.isAutoUpdate()) { mgr.update(target); } - } else if (this instanceof Expression) { + } else { // If expression was on autoupdate, update all the other expression // assigning may have side effects i.e. affecting other expressions. - ExpressionManager mgr = (ExpressionManager)target.getSession().getExpressionManager(); - if (mgr.isAutoUpdate()) { - mgr.update(target); + ExpressionManager expMgr = ((Session)target.getSession()).getExpressionManager(); + if (expMgr.isAutoUpdate()) { + expMgr.update(target); } - } else { + // FIXME: Should we always call the Variable Manager ? - VariableManager mgr = (VariableManager)target.getSession().getVariableManager(); - if (mgr.isAutoUpdate()) { - mgr.update(target); + VariableManager varMgr = (VariableManager)target.getSession().getVariableManager(); + if (varMgr.isAutoUpdate()) { + varMgr.update(target); } } }