mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Fix expression manager
This commit is contained in:
parent
cbf89ce619
commit
2a6c0b8c16
6 changed files with 80 additions and 102 deletions
|
@ -18,17 +18,24 @@ import java.util.Map;
|
|||
|
||||
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.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;
|
||||
|
||||
/**
|
||||
|
@ -37,11 +44,13 @@ public class ExpressionManager extends Manager {
|
|||
|
||||
final static ICDIExpression[] EMPTY_EXPRESSIONS = {};
|
||||
Map expMap;
|
||||
List variableList;
|
||||
MIVarChange[] noChanges = new MIVarChange[0];
|
||||
|
||||
public ExpressionManager(Session session) {
|
||||
super(session, true);
|
||||
expMap = new Hashtable();
|
||||
variableList = Collections.synchronizedList(new ArrayList());
|
||||
}
|
||||
|
||||
synchronized List getExpressionList(Target target) {
|
||||
|
@ -79,7 +88,6 @@ public class ExpressionManager extends Manager {
|
|||
for (int i = 0; i < expressions.length; ++i) {
|
||||
if (expressions[i] instanceof Expression) {
|
||||
expList.remove(expressions[i]);
|
||||
((Expression)expressions[i]).deleteVariable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,10 +104,9 @@ public class ExpressionManager extends Manager {
|
|||
List eventList = new ArrayList();
|
||||
MISession mi = target.getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
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();
|
||||
Variable[] vars = (Variable[])variableList.toArray(new Variable[0]);
|
||||
for (int i = 0; i < vars.length; i++) {
|
||||
Variable variable = vars[i];
|
||||
if (variable != null) {
|
||||
String varName = variable.getMIVar().getVarName();
|
||||
MIVarChange[] changes = noChanges;
|
||||
|
@ -132,20 +139,68 @@ public class ExpressionManager extends Manager {
|
|||
* @param varName
|
||||
* @return
|
||||
*/
|
||||
public Expression getExpression(MISession miSession, String varName) {
|
||||
public Variable getVariable(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];
|
||||
}
|
||||
Variable[] vars = (Variable[])variableList.toArray(new Variable[0]);
|
||||
for (int i = 0; i < vars.length; i++) {
|
||||
if (vars[i].getMIVar().getVarName().equals(varName)) {
|
||||
return vars[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Variable createVariable(ICDIStackFrame frame, String code) throws CDIException {
|
||||
Target target = (Target)frame.getTarget();
|
||||
ICDIThread currentThread = target.getCurrentThread();
|
||||
ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame();
|
||||
target.setCurrentThread(frame.getThread(), false);
|
||||
frame.getThread().setCurrentStackFrame(frame, false);
|
||||
try {
|
||||
MISession mi = target.getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarCreate var = factory.createMIVarCreate(code);
|
||||
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, code, frame, 0, 0);
|
||||
Variable variable = new Variable(varObj, info.getMIVar());
|
||||
variableList.add(variable);
|
||||
return variable;
|
||||
} catch (MIException e) {
|
||||
throw new MI2CDIException(e);
|
||||
} finally {
|
||||
target.setCurrentThread(currentThread, false);
|
||||
currentThread.setCurrentStackFrame(currentFrame, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rid of the underlying variable.
|
||||
*
|
||||
*/
|
||||
public void deleteVariable(Variable variable) throws CDIException {
|
||||
Target target = (Target)variable.getTarget();
|
||||
MISession miSession = target.getMISession();
|
||||
MIVar miVar = variable.getMIVar();
|
||||
removeMIVar(miSession, variable.getMIVar());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.eclipse.cdt.debug.mi.core.GDBTypeParser.GDBType;
|
|||
import org.eclipse.cdt.debug.mi.core.cdi.model.Instruction;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.MixedInstruction;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.VariableObject;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.ArrayType;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.BoolType;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.CharType;
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ChangedEvent implements ICDIChangedEvent {
|
|||
// Try the Expression manager
|
||||
if (source == null) {
|
||||
ExpressionManager expMgr = session.getExpressionManager();
|
||||
source = expMgr.getExpression(miSession, varName);
|
||||
source = expMgr.getVariable(miSession, varName);
|
||||
}
|
||||
|
||||
// Try the Register manager
|
||||
|
@ -94,7 +94,7 @@ public class ChangedEvent implements ICDIChangedEvent {
|
|||
|
||||
public ChangedEvent(Session s, MISharedLibChangedEvent slib) {
|
||||
session = s;
|
||||
SharedLibraryManager mgr = (SharedLibraryManager)session.getSharedLibraryManager();
|
||||
SharedLibraryManager mgr = session.getSharedLibraryManager();
|
||||
MISession miSession = slib.getMISession();
|
||||
String name = slib.getName();
|
||||
ICDISharedLibrary lib = mgr.getSharedLibrary(miSession, name);
|
||||
|
|
|
@ -109,7 +109,7 @@ public class CreatedEvent implements ICDICreatedEvent {
|
|||
|
||||
public CreatedEvent(Session s, MISharedLibCreatedEvent slib) {
|
||||
session = s;
|
||||
SharedLibraryManager mgr = (SharedLibraryManager)session.getSharedLibraryManager();
|
||||
SharedLibraryManager mgr = session.getSharedLibraryManager();
|
||||
MISession miSession = slib.getMISession();
|
||||
String name = slib.getName();
|
||||
source = mgr.getSharedLibrary(miSession, name);
|
||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
@ -58,13 +57,9 @@ public class DestroyedEvent implements ICDIDestroyedEvent {
|
|||
}
|
||||
} else {
|
||||
ExpressionManager expMgr = session.getExpressionManager();
|
||||
Expression expression = expMgr.getExpression(miSession, varName);
|
||||
if (expression != null) {
|
||||
source = expression;
|
||||
try {
|
||||
expression.deleteVariable();
|
||||
} catch (CDIException e) {
|
||||
}
|
||||
variable = expMgr.getVariable(miSession, varName);
|
||||
if (variable != null) {
|
||||
source = variable;
|
||||
} else {
|
||||
Target target = session.getTarget(miSession);
|
||||
source = new CObject(target);
|
||||
|
@ -89,7 +84,7 @@ public class DestroyedEvent implements ICDIDestroyedEvent {
|
|||
|
||||
public DestroyedEvent(Session s, MISharedLibUnloadedEvent slib) {
|
||||
session = s;
|
||||
SharedLibraryManager mgr = (SharedLibraryManager)session.getSharedLibraryManager();
|
||||
SharedLibraryManager mgr = session.getSharedLibraryManager();
|
||||
MISession miSession = slib.getMISession();
|
||||
String name = slib.getName();
|
||||
ICDISharedLibrary lib = mgr.getSharedLibrary(miSession, name);
|
||||
|
|
|
@ -13,22 +13,13 @@ 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.core.cdi.model.type.ICDIType;
|
||||
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.ExpressionManager;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.SourceManager;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.IncompleteType;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.Type;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,7 +29,6 @@ public class Expression extends CObject implements ICDIExpression {
|
|||
private static int ID_COUNT = 0;
|
||||
private int id;
|
||||
String fExpression;
|
||||
Variable fVariable;
|
||||
Type fType;
|
||||
|
||||
public Expression(Target target, String ex) {
|
||||
|
@ -104,71 +94,10 @@ public class Expression extends CObject implements ICDIExpression {
|
|||
* @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 target = (Target)frame.getTarget();
|
||||
ICDIThread currentThread = target.getCurrentThread();
|
||||
ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame();
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
ExpressionManager mgr = session.getExpressionManager();
|
||||
Variable var = mgr.createVariable(context, getExpressionText());
|
||||
return var.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue