From 87abcdb98ab4a8dbfdc4979fb8679434c999e317 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Wed, 12 Feb 2003 05:26:24 +0000 Subject: [PATCH] New method removeExpression --- .../debug/mi/core/cdi/ExpressionManager.java | 71 +++++++++++++++---- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java index 38648559af4..d5ddecd9ead 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/ExpressionManager.java @@ -18,12 +18,16 @@ 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.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; @@ -42,8 +46,35 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa autoupdate = true; } - synchronized private void addExpression(Expression exp) { - expList.add(exp); + /** + * Tell gdb to remove the underlying var-object also. + */ + void removeMIVar(MIVar miVar) throws CDIException { + Session session = (Session)getSession(); + MISession mi = session.getMISession(); + CommandFactory factory = mi.getCommandFactory(); + MIVarDelete var = factory.createMIVarDelete(miVar.getVarName()); + try { + mi.postCommand(var); + var.getMIInfo(); + } catch (MIException e) { + throw new MI2CDIException(e); + } + } + + /** + * When element are remove from the cache, they are put on the OutOfScope list, oos, + * because they are still needed for the destroy events. The destroy event will + * call removeOutOfScope. + */ + public void removeExpression(String varName) throws CDIException { + Expression[] exps = (Expression[])expList.toArray(new Expression[0]); + for (int i = 0; i < exps.length; i++) { + if (exps[i].getMIVar().getVarName().equals(varName)) { + expList.remove(exps[i]); + removeMIVar(exps[i].getMIVar()); + } + } } /** @@ -64,7 +95,7 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa } VariableObject varObj = new VariableObject(currentTarget, name, null, 0, 0); expression = new Expression(varObj, info.getMIVar()); - addExpression(expression); + expList.add(expression); } catch (MIException e) { throw new MI2CDIException(e); } @@ -93,7 +124,7 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa ICDITarget tgt = frame.getThread().getTarget(); VariableObject varObj = new VariableObject(tgt, name, frame, 0, 0); expression = new Expression(varObj, info.getMIVar()); - addExpression(expression); + expList.add(expression); } catch (MIException e) { throw new MI2CDIException(e); } finally { @@ -109,30 +140,34 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa return (ICDIExpression[])expList.toArray(new ICDIExpression[0]); } - /** - * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#destroyExpression(ICDIExpression) - */ - synchronized public void removeExpression(ICDIExpression expression) throws CDIException { - expList.remove(expression); - } - /** * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression) */ public void destroyExpression(ICDIExpression expression) throws CDIException { - removeExpression(expression); + if (expression instanceof Expression) { + // Fire a destroyEvent ? + Expression exp= (Expression)expression; + MIVarDeletedEvent del = new MIVarDeletedEvent(exp.getMIVar().getVarName()); + Session session = (Session)getSession(); + MISession mi = session.getMISession(); + mi.fireEvent(del); + } } /** * Return the element that have the uniq varName. * null is return if the element is not in the cache. */ - public Expression getExpression(String varName) { + public Variable getExpression(String varName) { Expression[] exps = (Expression[])expList.toArray(new Expression[0]); 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; } @@ -159,11 +194,17 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa changes = info.getMIVarChanges(); } catch (MIException e) { //throw new MI2CDIException(e); - eventList.add(new MIVarChangedEvent(0, varName, false)); + eventList.add(new MIVarDeletedEvent(varName)); } for (int j = 0 ; j < changes.length; j++) { String n = changes[j].getVarName(); - eventList.add(new MIVarChangedEvent(0, n, changes[j].isInScope())); + if (changes[j].isInScope()) { + eventList.add(new MIVarChangedEvent(n)); + } + // We do not implicitely delete Expressions. + //else { + // eventList.add(new MIVarDeletedEvent(n)); + //} } } MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);