mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
The use of MI Variable Objects for the CDI bridge implementation.
This commit is contained in:
parent
893ef39e38
commit
501c326a4b
16 changed files with 659 additions and 270 deletions
|
@ -12,7 +12,7 @@ import org.eclipse.cdt.debug.core.cdi.CDIException;
|
|||
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIDebugConfiguration;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIEventManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIRuntimeOptions;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISession;
|
||||
|
@ -31,7 +31,8 @@ public class CSession implements ICDISession, ICDISessionObject {
|
|||
MISession session;
|
||||
BreakpointManager breakpointManager;
|
||||
EventManager eventManager;
|
||||
VariableManager expressionManager;
|
||||
ExpressionManager expressionManager;
|
||||
VariableManager variableManager;
|
||||
MemoryManager memoryManager;
|
||||
SignalManager signalManager;
|
||||
SourceManager sourceManager;
|
||||
|
@ -43,7 +44,8 @@ public class CSession implements ICDISession, ICDISessionObject {
|
|||
breakpointManager = new BreakpointManager(this);
|
||||
eventManager = new EventManager(this);
|
||||
s.addObserver(eventManager);
|
||||
expressionManager = new VariableManager(this);
|
||||
expressionManager = new ExpressionManager(this);
|
||||
variableManager = new VariableManager(this);
|
||||
memoryManager = new MemoryManager(this);
|
||||
signalManager = new SignalManager(this);
|
||||
sourceManager = new SourceManager(this);
|
||||
|
@ -54,10 +56,6 @@ public class CSession implements ICDISession, ICDISessionObject {
|
|||
return session;
|
||||
}
|
||||
|
||||
ICDITarget getTarget() {
|
||||
return ctarget;
|
||||
}
|
||||
|
||||
CTarget getCTarget() {
|
||||
return ctarget;
|
||||
}
|
||||
|
@ -86,10 +84,16 @@ public class CSession implements ICDISession, ICDISessionObject {
|
|||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getVariableManager()
|
||||
*/
|
||||
public ICDIVariableManager getVariableManager() {
|
||||
public ICDIExpressionManager getExpressionManager() {
|
||||
return expressionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public VariableManager getVariableManager() {
|
||||
return variableManager;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getMemoryManager()
|
||||
*/
|
||||
|
@ -118,6 +122,23 @@ public class CSession implements ICDISession, ICDISessionObject {
|
|||
return new ICDITarget[]{ctarget};
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getCurrentTarget()
|
||||
*/
|
||||
public ICDITarget getCurrentTarget() {
|
||||
return ctarget;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void setCurrentTarget(ICDITarget target) throws CDIException {
|
||||
if (target instanceof CTarget) {
|
||||
ctarget = (CTarget)target;
|
||||
return;
|
||||
}
|
||||
throw new CDIException("Unkown target");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#setAttribute(String, String)
|
||||
*/
|
||||
|
|
|
@ -9,9 +9,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISession;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariable;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterGroup;
|
||||
|
@ -19,6 +18,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary;
|
|||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||
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.ICDIVariable;
|
||||
import org.eclipse.cdt.debug.mi.core.MIException;
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
|
@ -33,9 +33,11 @@ import org.eclipse.cdt.debug.mi.core.command.MIExecStep;
|
|||
import org.eclipse.cdt.debug.mi.core.command.MIExecStepInstruction;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MITargetDetach;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIThreadListIds;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIThreadSelect;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIDataEvaluateExpressionInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIThreadListIdsInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIThreadSelectInfo;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -49,7 +51,7 @@ public class CTarget implements ICDITarget {
|
|||
public CTarget(CSession s) {
|
||||
session = s;
|
||||
threadList = new ArrayList(1);
|
||||
dummyThread = new CThread(this, 0);
|
||||
dummyThread = new CThread(this, 1);
|
||||
currentThread = dummyThread;
|
||||
threadList.add(dummyThread);
|
||||
}
|
||||
|
@ -67,13 +69,20 @@ public class CTarget implements ICDITarget {
|
|||
}
|
||||
|
||||
void setCurrentThread(int id) {
|
||||
for (int i = 0; i < threadList.size(); i++) {
|
||||
CThread cthread = (CThread)threadList.get(i);
|
||||
if (cthread.getId() == id) {
|
||||
currentThread = cthread;
|
||||
return ;
|
||||
CThread cthread = null;
|
||||
if (containsCThread(id)) {
|
||||
for (int i = 0; i < threadList.size(); i++) {
|
||||
CThread thread = (CThread)threadList.get(i);
|
||||
if (thread.getId() == id) {
|
||||
cthread = thread;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cthread = new CThread(this, id);
|
||||
addCThread(cthread);
|
||||
}
|
||||
currentThread = cthread;
|
||||
}
|
||||
|
||||
boolean containsCThread(int id) {
|
||||
|
@ -101,7 +110,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(detach);
|
||||
MIInfo info = detach.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -119,7 +128,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(finish);
|
||||
MIInfo info = finish.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -163,12 +172,30 @@ public class CTarget implements ICDITarget {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getCurrentThread()
|
||||
*/
|
||||
public ICDIThread getCurrentThread() throws CDIException {
|
||||
public CThread getCurrentThread() throws CDIException {
|
||||
return currentThread;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void setCurrentThread(CThread cthread) throws CDIException {
|
||||
session.setCurrentTarget(this);
|
||||
int id = cthread.getId();
|
||||
session.setCurrentTarget(this);
|
||||
MISession mi = session.getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIThreadSelect select = factory.createMIThreadSelect(id);
|
||||
try {
|
||||
mi.postCommand(select);
|
||||
MIThreadSelectInfo info = select.getMIThreadSelectInfo();
|
||||
int newId = info.getNewThreadId();
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
setCurrentThread(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getThreads()
|
||||
*/
|
||||
|
@ -182,7 +209,7 @@ public class CTarget implements ICDITarget {
|
|||
int[] ids = info.getThreadIds();
|
||||
if (ids != null && ids.length > 0) {
|
||||
// Ok that means it is a multiThreaded, remove the dummy Thread
|
||||
removeCThread(dummyThread);
|
||||
//removeCThread(dummyThread);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
if (! containsCThread(ids[i])) {
|
||||
addCThread(new CThread(this, ids[i]));
|
||||
|
@ -227,7 +254,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(run);
|
||||
MIInfo info = run.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -248,7 +275,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(cont);
|
||||
MIInfo info = cont.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -272,7 +299,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(step);
|
||||
MIInfo info = step.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -290,7 +317,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(stepi);
|
||||
MIInfo info = stepi.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -308,7 +335,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(next);
|
||||
MIInfo info = next.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -326,7 +353,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(nexti);
|
||||
MIInfo info = nexti.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -344,7 +371,7 @@ public class CTarget implements ICDITarget {
|
|||
mi.postCommand(interrupt);
|
||||
MIInfo info = interrupt.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
|
@ -380,7 +407,7 @@ public class CTarget implements ICDITarget {
|
|||
MIDataEvaluateExpressionInfo info =
|
||||
evaluate.getMIDataEvaluateExpressionInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
return info.getExpression();
|
||||
} catch (MIException e) {
|
||||
|
@ -393,11 +420,9 @@ public class CTarget implements ICDITarget {
|
|||
*/
|
||||
public ICDIValue evaluateExpressionToValue(String expressionText)
|
||||
throws CDIException {
|
||||
ICDIVariableManager mgr = session.getVariableManager();
|
||||
ICDIExpression cexp = mgr.createExpression(expressionText);
|
||||
ICDIValue value = cexp.getValue();
|
||||
mgr.removeExpression(cexp);
|
||||
return value;
|
||||
VariableManager mgr = session.getVariableManager();
|
||||
ICDIVariable var = mgr.createVariable(expressionText);
|
||||
return var.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -406,5 +431,5 @@ public class CTarget implements ICDITarget {
|
|||
public ICDISession getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,20 +7,17 @@ import org.eclipse.cdt.debug.mi.core.MIException;
|
|||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIStackListFrames;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIStackSelectFrame;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIFrame;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIStackListFramesInfo;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class CThread extends CObject implements ICDIThread {
|
||||
|
||||
int id;
|
||||
StackFrame currentStackFrame;
|
||||
|
||||
public CThread(CTarget target, int threadId) {
|
||||
super(target);
|
||||
|
@ -53,12 +50,15 @@ public class CThread extends CObject implements ICDIThread {
|
|||
mi.postCommand(frames);
|
||||
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("Timedout");
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
MIFrame[] miFrames = info.getMIFrames();
|
||||
ICDIStackFrame[] stack = new ICDIStackFrame[miFrames.length];
|
||||
StackFrame[] stack = new StackFrame[miFrames.length];
|
||||
for (int i = 0; i < stack.length; i++) {
|
||||
stack[i] = new StackFrame(getCTarget(), miFrames[i]);
|
||||
stack[i] = new StackFrame(this, miFrames[i]);
|
||||
if (i == 0) {
|
||||
currentStackFrame = stack[i];
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
} catch (MIException e) {
|
||||
|
@ -66,6 +66,33 @@ public class CThread extends CObject implements ICDIThread {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#setCurrentStackFrame(ICDIStackFrame)
|
||||
*/
|
||||
public void setCurrentStackFrame(StackFrame stackframe) throws CDIException {
|
||||
getCTarget().setCurrentThread(this);
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
int frameNum = stackframe.getLevel();
|
||||
MIStackSelectFrame frame = factory.createMIStackSelectFrame(frameNum);
|
||||
try {
|
||||
mi.postCommand(frame);
|
||||
MIInfo info = frame.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
currentStackFrame = (StackFrame)stackframe;
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public StackFrame getCurrentStackFrame() throws CDIException {
|
||||
return currentStackFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#isSuspended()
|
||||
*/
|
||||
|
@ -115,4 +142,15 @@ public class CThread extends CObject implements ICDIThread {
|
|||
getTarget().suspend();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#equals(ICDIThread)
|
||||
*/
|
||||
public boolean equals(ICDIThread thread) {
|
||||
if (thread instanceof CThread) {
|
||||
CThread cthread = (CThread) thread;
|
||||
return id == cthread.getId();
|
||||
}
|
||||
return super.equals(thread);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
||||
import org.eclipse.cdt.debug.mi.core.event.MIEvent;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class ChangedEvent implements ICDIChangedEvent {
|
||||
|
||||
CSession session;
|
||||
MIEvent event;
|
||||
|
||||
public ChangedEvent(CSession s, MIEvent e) {
|
||||
session = s;
|
||||
event = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEvent#getSource()
|
||||
*/
|
||||
public ICDIObject getSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -80,6 +80,10 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
|
|||
}
|
||||
|
||||
// Fire the event;
|
||||
fireEvent(cdiEvent);
|
||||
}
|
||||
|
||||
public void fireEvent(ICDIEvent cdiEvent) {
|
||||
if (cdiEvent != null) {
|
||||
ICDIEventListener[] listeners =
|
||||
(ICDIEventListener[])list.toArray(new ICDIEventListener[0]);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ExitedEvent implements ICDIExitedEvent {
|
|||
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEvent#getSource()
|
||||
*/
|
||||
public ICDIObject getSource() {
|
||||
return session.getTarget();
|
||||
return session.getCurrentTarget();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,91 +1,13 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
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.ICDIValue;
|
||||
import org.eclipse.cdt.debug.mi.core.MIException;
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarAssign;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarEvaluateExpression;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIChild;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVarEvaluateExpressionInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVar;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class Expression extends CObject implements ICDIExpression {
|
||||
public class Expression extends Variable implements ICDIExpression {
|
||||
|
||||
MIChild child;
|
||||
String exp;
|
||||
|
||||
public Expression(CTarget target, String e, MIChild c) {
|
||||
super(target);
|
||||
exp = e;
|
||||
child = c;
|
||||
public Expression(StackFrame stackframe, String name, MIVar var) {
|
||||
super(stackframe, name, var);
|
||||
}
|
||||
|
||||
String getVarName() {
|
||||
return child.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getName()
|
||||
*/
|
||||
public String getName() throws CDIException {
|
||||
return exp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getTypeName()
|
||||
*/
|
||||
public String getTypeName() throws CDIException {
|
||||
return child.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue()
|
||||
*/
|
||||
public ICDIValue getValue() throws CDIException {
|
||||
Value cvalue;
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarEvaluateExpression var = factory.createMIVarEvaluateExpression(getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarEvaluateExpressionInfo info = var.getMIVarEvaluateExpressionInfo();
|
||||
String value = info.getValue();
|
||||
cvalue = new Value(getCTarget(), value);
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
return cvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(ICDIValue)
|
||||
*/
|
||||
public void setValue(ICDIValue value) throws CDIException {
|
||||
setValue(value.getValueString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(String)
|
||||
*/
|
||||
public void setValue(String expression) throws CDIException {
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarAssign var = factory.createMIVarAssign(getVarName(), expression);
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDICondition;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class ExpressionManager extends SessionObject implements ICDIExpressionManager {
|
||||
|
||||
public ExpressionManager(CSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createCondition(int, String)
|
||||
*/
|
||||
public ICDICondition createCondition(int ignoreCount, String expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(String)
|
||||
*/
|
||||
public ICDIExpression createExpression(String name) throws CDIException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getExpressions()
|
||||
*/
|
||||
public ICDIExpression[] getExpressions() throws CDIException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression)
|
||||
*/
|
||||
public void removeExpression(ICDIExpression expression)
|
||||
throws CDIException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpressions(ICDIExpression[])
|
||||
*/
|
||||
public void removeExpressions(ICDIExpression[] expressions)
|
||||
throws CDIException {
|
||||
}
|
||||
|
||||
}
|
|
@ -71,4 +71,18 @@ public class Location implements ICDILocation {
|
|||
public int getLineNumber() {
|
||||
return line;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDILocation#equals(ICDILocation)
|
||||
*/
|
||||
public boolean equals(ICDILocation location) {
|
||||
if (location instanceof Location) {
|
||||
Location loc = (Location)location;
|
||||
return addr == loc.getAddress() &&
|
||||
file.equals(loc.getFile()) &&
|
||||
function.equals(loc.getFunction()) &&
|
||||
line == loc.getLineNumber();
|
||||
}
|
||||
return super.equals(location);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVar;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class Register extends Variable implements ICDIRegister {
|
||||
|
||||
public Register(StackFrame frame, String name, MIVar var) {
|
||||
super(frame, name, var);
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ public class ResumedEvent implements ICDIResumedEvent {
|
|||
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEvent#getSource()
|
||||
*/
|
||||
public ICDIObject getSource() {
|
||||
return session.getTarget();
|
||||
return session.getCurrentTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,43 +20,61 @@ import org.eclipse.cdt.debug.mi.core.output.MIStackListLocalsInfo;
|
|||
public class StackFrame extends CObject implements ICDIStackFrame {
|
||||
|
||||
MIFrame frame;
|
||||
CThread cthread;
|
||||
|
||||
public StackFrame(CTarget target, MIFrame f) {
|
||||
super(target);
|
||||
public StackFrame(CThread thread, MIFrame f) {
|
||||
super(thread.getCTarget());
|
||||
cthread = thread;
|
||||
frame = f;
|
||||
}
|
||||
|
||||
MIFrame getMIFrame() {
|
||||
return frame;
|
||||
}
|
||||
|
||||
CThread getCThread() {
|
||||
return cthread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getArguments()
|
||||
*/
|
||||
public ICDIArgument[] getArguments() throws CDIException {
|
||||
MIArg[] args = null;
|
||||
ICDIArgument[] cdiArgs = null;
|
||||
if (frame != null) {
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CSession session = getCTarget().getCSession();
|
||||
VariableManager mgr = (VariableManager)session.getVariableManager();
|
||||
mgr.update();
|
||||
MISession mi = session.getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
int level = frame.getLevel();
|
||||
MIStackListArguments listArgs =
|
||||
factory.createMIStackListArguments(true, level, level);
|
||||
factory.createMIStackListArguments(false, level, level);
|
||||
try {
|
||||
MIArg[] args = null;
|
||||
mi.postCommand(listArgs);
|
||||
MIStackListArgumentsInfo info = listArgs.getMIStackListArgumentsInfo();
|
||||
MIStackListArgumentsInfo info =
|
||||
listArgs.getMIStackListArgumentsInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
MIFrame[] miFrames = info.getMIFrames();
|
||||
if (miFrames != null && miFrames.length == 1) {
|
||||
args = miFrames[0].getArgs();
|
||||
}
|
||||
if (args != null) {
|
||||
cdiArgs = new ICDIArgument[args.length];
|
||||
for (int i = 0; i < cdiArgs.length; i++) {
|
||||
cdiArgs[i] =
|
||||
mgr.createArgument(this, args[i].getName());
|
||||
}
|
||||
} else {
|
||||
cdiArgs = new ICDIArgument[0];
|
||||
}
|
||||
} catch (MIException e) {
|
||||
//throw new CDIException(e);
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
if (args != null) {
|
||||
cdiArgs = new ICDIArgument[args.length];
|
||||
for (int i = 0; i < cdiArgs.length; i++) {
|
||||
cdiArgs[i] = new Argument(getCTarget(), args[i]);
|
||||
}
|
||||
} else {
|
||||
cdiArgs = new ICDIArgument[0];
|
||||
}
|
||||
return cdiArgs;
|
||||
}
|
||||
|
||||
|
@ -64,31 +82,33 @@ public class StackFrame extends CObject implements ICDIStackFrame {
|
|||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getLocalVariables()
|
||||
*/
|
||||
public ICDIVariable[] getLocalVariables() throws CDIException {
|
||||
MIArg[] args = null;
|
||||
ICDIVariable[] variables = null;
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CSession session = getCTarget().getCSession();
|
||||
VariableManager mgr = (VariableManager)session.getVariableManager();
|
||||
mgr.update();
|
||||
MISession mi = session.getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIStackListLocals locals = factory.createMIStackListLocals(true);
|
||||
MIStackListLocals locals = factory.createMIStackListLocals(false);
|
||||
try {
|
||||
MIArg[] args = null;
|
||||
ICDIVariable[] variables = null;
|
||||
mi.postCommand(locals);
|
||||
MIStackListLocalsInfo info = locals.getMIStackListLocalsInfo();
|
||||
if (info == null) {
|
||||
// throw new CDIException();
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
args = info.getLocals();
|
||||
|
||||
} catch (MIException e) {
|
||||
//throw new CDIException(e);
|
||||
}
|
||||
if (args != null) {
|
||||
variables = new ICDIVariable[args.length];
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
variables[i] = new Variable(getCTarget(), args[i]);
|
||||
if (args != null) {
|
||||
variables = new ICDIVariable[args.length];
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
variables[i] = mgr.createVariable(this, args[i].getName());
|
||||
}
|
||||
} else {
|
||||
variables = new ICDIVariable[0];
|
||||
}
|
||||
} else {
|
||||
variables = new ICDIVariable[0];
|
||||
return variables;
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,4 +131,20 @@ public class StackFrame extends CObject implements ICDIStackFrame {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#equals(ICDIStackFrame)
|
||||
*/
|
||||
public boolean equals(ICDIStackFrame stackframe) {
|
||||
if (stackframe instanceof StackFrame) {
|
||||
StackFrame stack = (StackFrame)stackframe;
|
||||
return cthread != null &&
|
||||
cthread.equals(stack.getCThread()) &&
|
||||
frame != null &&
|
||||
frame.getLevel() == stack.getMIFrame().getLevel() &&
|
||||
frame.getFile().equals(stack.getMIFrame().getFile()) &&
|
||||
frame.getFunction().equals(stack.getMIFrame().getFunction());
|
||||
}
|
||||
return super.equals(stackframe);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,25 +29,17 @@ public class SuspendedEvent implements ICDISuspendedEvent {
|
|||
}
|
||||
|
||||
public ICDISessionObject getReason() {
|
||||
if (event instanceof MIBreakpointEvent
|
||||
|| event instanceof MIWatchpointEvent) {
|
||||
MIBreakpointEvent breakEvent = (MIBreakpointEvent) event;
|
||||
if (event instanceof MIBreakpointEvent || event instanceof MIWatchpointEvent) {
|
||||
MIBreakpointEvent breakEvent = (MIBreakpointEvent)event;
|
||||
int number = breakEvent.getNumber();
|
||||
ICDIBreakpointManager mgr = session.getBreakpointManager();
|
||||
// Ask the breakpoint manager the array of ICDIBreakpoint(s)
|
||||
BreakpointManager mgr = (BreakpointManager)session.getBreakpointManager();
|
||||
// Ask the breakpointManager for the breakpoint
|
||||
// We need to return the same object as the reason.
|
||||
try {
|
||||
ICDIBreakpoint[] bkpts = mgr.getBreakpoints();
|
||||
for (int i = 0; i < bkpts.length; i++) {
|
||||
if (bkpts[i] instanceof Breakpoint) {
|
||||
Breakpoint point = (Breakpoint) bkpts[i];
|
||||
MIBreakPoint miBreak = point.getMIBreakPoint();
|
||||
if (miBreak.getNumber() == number) {
|
||||
return point;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CDIException e) {
|
||||
Breakpoint point = mgr.getBreakpoint(number);
|
||||
if (point != null) {
|
||||
return point;
|
||||
} else {
|
||||
// FIXME: Create a new breakpoint.
|
||||
}
|
||||
} else if (event instanceof MISteppingRangeEvent) {
|
||||
return new EndSteppingRange(session);
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
||||
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.mi.core.MIException;
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarEvaluateExpression;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarListChildren;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVar;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVarEvaluateExpressionInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVarListChildrenInfo;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
|
@ -16,32 +22,71 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
|
|||
*/
|
||||
public class Value extends CObject implements ICDIValue {
|
||||
|
||||
String val = "";
|
||||
Variable variable;
|
||||
|
||||
public Value(CTarget target, String s) {
|
||||
super(target);
|
||||
val = s;
|
||||
public Value(Variable v) {
|
||||
super(v.getCTarget());
|
||||
variable = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getTypeName()
|
||||
*/
|
||||
public String getTypeName() throws CDIException {
|
||||
return "";
|
||||
return variable.getTypeName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getValueString()
|
||||
*/
|
||||
public String getValueString() throws CDIException {
|
||||
return val;
|
||||
String result = "";
|
||||
StackFrame stack = variable.getStackFrame();
|
||||
stack.getCThread().setCurrentStackFrame(stack);
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarEvaluateExpression var =
|
||||
factory.createMIVarEvaluateExpression(variable.getMIVar().getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarEvaluateExpressionInfo info = var.getMIVarEvaluateExpressionInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
result = info.getValue();
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIValue#getVariables()
|
||||
*/
|
||||
public ICDIVariable[] getVariables() throws CDIException {
|
||||
return new ICDIVariable[0];
|
||||
StackFrame stack = variable.getStackFrame();
|
||||
stack.getCThread().setCurrentStackFrame(stack);
|
||||
Variable[] variables = null;
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarListChildren var =
|
||||
factory.createMIVarListChildren(variable.getMIVar().getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarListChildrenInfo info = var.getMIVarListChildrenInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
MIVar[] vars = info.getMIVars();
|
||||
variables = new Variable[vars.length];
|
||||
for (int i = 0; i < vars.length; i++) {
|
||||
variables[i] =
|
||||
new Variable(variable.getStackFrame(), vars[i].getExp(), vars[i]);
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,66 +1,118 @@
|
|||
package org.eclipse.cdt.debug.mi.core.cdi;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
||||
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.mi.core.output.MIArg;
|
||||
import org.eclipse.cdt.debug.mi.core.MIException;
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarAssign;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarShowAttributes;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVar;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIVarShowAttributesInfo;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class Variable extends CObject implements ICDIVariable {
|
||||
|
||||
MIArg arg;
|
||||
MIVar miVar;
|
||||
String name;
|
||||
Value value;
|
||||
StackFrame stack;
|
||||
|
||||
public Variable(CTarget target, MIArg a) {
|
||||
super(target);
|
||||
arg = a;
|
||||
public Variable(StackFrame stackframe, String n, MIVar v) {
|
||||
super(stackframe.getCTarget());
|
||||
stack = stackframe;
|
||||
name = n;
|
||||
miVar = v;
|
||||
}
|
||||
|
||||
StackFrame getStackFrame() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
MIVar getMIVar() {
|
||||
return miVar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getName()
|
||||
*/
|
||||
public String getName() throws CDIException {
|
||||
return arg.getName();
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getTypeName()
|
||||
*/
|
||||
public String getTypeName() throws CDIException {
|
||||
return "";
|
||||
return miVar.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue()
|
||||
*/
|
||||
public ICDIValue getValue() throws CDIException {
|
||||
return new Value(getCTarget(), arg.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#hasValueChanged()
|
||||
*/
|
||||
public boolean hasValueChanged() throws CDIException {
|
||||
return false;
|
||||
if (value == null) {
|
||||
value = new Value(this);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(ICDIValue)
|
||||
*/
|
||||
public void setValue(ICDIValue value) throws CDIException {
|
||||
setValue(value.getValueString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(String)
|
||||
*/
|
||||
public void setValue(String expression) throws CDIException {
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarAssign var = factory.createMIVarAssign(miVar.getVarName(), expression);
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIInfo info = var.getMIInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#isEditable()
|
||||
*/
|
||||
public boolean isEditable() throws CDIException {
|
||||
MISession mi = getCTarget().getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarShowAttributes var = factory.createMIVarShowAttributes(miVar.getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarShowAttributesInfo info = var.getMIVarShowAttributesInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
return info.isEditable();
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#equals()
|
||||
*/
|
||||
public boolean equals(ICDIVariable var) {
|
||||
if (var instanceof Variable) {
|
||||
Variable variable = (Variable)var;
|
||||
return miVar.getVarName().equals(variable.getMIVar().getVarName());
|
||||
}
|
||||
return super.equals(var);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,110 +10,248 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDICondition;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
|
||||
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.core.cdi.model.ICDIVariable;
|
||||
import org.eclipse.cdt.debug.mi.core.MIException;
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
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.MIChild;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIVarUpdate;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class VariableManager
|
||||
extends SessionObject
|
||||
implements ICDIVariableManager {
|
||||
public class VariableManager extends SessionObject {
|
||||
|
||||
List elementList;
|
||||
|
||||
/**
|
||||
* Class container to regroup all info concerning a variable.
|
||||
*/
|
||||
class Element {
|
||||
MIVar miVar;
|
||||
String name;
|
||||
StackFrame stackframe;
|
||||
Variable variable;
|
||||
}
|
||||
|
||||
List expList;
|
||||
public VariableManager(CSession session) {
|
||||
super(session);
|
||||
expList = new ArrayList();
|
||||
elementList = new ArrayList();
|
||||
}
|
||||
|
||||
Element getElement(StackFrame stack, String name) {
|
||||
Element[] elements = getElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
if (elements[i].stackframe.equals(stack) &&
|
||||
elements[i].name.equals(name)) {
|
||||
return elements[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void addElement(Element element) {
|
||||
Element[] elements = getElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
String name = elements[i].miVar.getVarName();
|
||||
if (name.equals(element.miVar.getVarName())) {
|
||||
// Thread.currentThread().dumpStack();
|
||||
return;
|
||||
}
|
||||
}
|
||||
elementList.add(element);
|
||||
}
|
||||
|
||||
Element[] getElements() {
|
||||
return (Element[]) elementList.toArray(new Element[0]);
|
||||
}
|
||||
|
||||
void update() throws CDIException {
|
||||
MISession mi = getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarUpdate update = factory.createMIVarUpdate();
|
||||
try {
|
||||
mi.postCommand(update);
|
||||
MIVarUpdateInfo info = update.getMIVarUpdateInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
MIVarChange[]changes = info.getMIVarChanges();
|
||||
for (int i = 0 ; i < changes.length; i++) {
|
||||
ICDIEvent cdiEvent;
|
||||
if (!changes[i].isInScope()) {
|
||||
//cdiEvent = DestroyEvent(getCSession(), );
|
||||
removeVariable(changes[i]);
|
||||
} else {
|
||||
//cdiEvent = ChangedEvent(getCSession(), );
|
||||
}
|
||||
//EventManager mgr = (EventManager)getCSession().getEventManager();
|
||||
//mgr.fireEvent(cdiEvent);
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Element createElement(StackFrame stack, String name) throws CDIException {
|
||||
Element element = getElement(stack, name);
|
||||
if (element == null) {
|
||||
stack.getCThread().setCurrentStackFrame(stack);
|
||||
MISession mi = getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarCreate var = factory.createMIVarCreate(name);
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarCreateInfo info = var.getMIVarCreateInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
element = new Element();
|
||||
element.miVar = info.getMIVar();
|
||||
element.name = name;
|
||||
element.stackframe = stack;
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getExpression(String)
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getVariable(String)
|
||||
*/
|
||||
public ICDIExpression getExpression(String expressionId)
|
||||
throws CDIException {
|
||||
ICDIExpression[] expressions = getExpressions();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (expressionId.equals(expressions[i].getName())) {
|
||||
return expressions[i];
|
||||
public ICDIVariable getVariable(String name) throws CDIException {
|
||||
ICDIVariable[] variables = getVariables();
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
if (name.equals(variables[i].getName())) {
|
||||
return variables[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getExpressions()
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getVariables()
|
||||
*/
|
||||
public ICDIExpression[] getExpressions() throws CDIException {
|
||||
return (ICDIExpression[]) expList.toArray(new ICDIExpression[0]);
|
||||
public ICDIVariable[] getVariables() throws CDIException {
|
||||
Element[] elements = getElements();
|
||||
ICDIVariable[] variables = new ICDIVariable[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
variables[i] = elements[i].variable;
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#removeExpression(ICDIExpression)
|
||||
*/
|
||||
public void removeExpression(ICDIExpression expression)
|
||||
throws CDIException {
|
||||
if (expression instanceof Expression) {
|
||||
expList.remove(expression);
|
||||
MISession mi = getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarDelete var =
|
||||
factory.createMIVarDelete(
|
||||
((Expression) expression).getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
void removeMIVar(MIVar miVar) throws CDIException {
|
||||
MISession mi = getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarDelete var = factory.createMIVarDelete(miVar.getVarName());
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIInfo info = var.getMIInfo();
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void removeVariable(String varName) throws CDIException {
|
||||
Element[] elements = getElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
if (elements[i].miVar.getVarName().equals(varName)) {
|
||||
elementList.remove(elements[i]);
|
||||
removeMIVar(elements[i].miVar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeVariable(MIVarChange changed) throws CDIException {
|
||||
String varName = changed.getVarName();
|
||||
removeVariable(varName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#removeExpressions(ICDIExpression[])
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeVariable(ICDIVariable)
|
||||
*/
|
||||
public void removeExpressions(ICDIExpression[] expressions)
|
||||
throws CDIException {
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
removeExpression(expressions[i]);
|
||||
public void removeVariable(ICDIVariable variable) throws CDIException {
|
||||
if (variable instanceof Variable) {
|
||||
String varName = ((Variable)variable).getMIVar().getVarName();
|
||||
removeVariable(varName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#createExpression(String)
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeVariable(ICDIVariable[])
|
||||
*/
|
||||
public ICDIExpression createExpression(String expressionId)
|
||||
throws CDIException {
|
||||
|
||||
Expression cexp = null;
|
||||
|
||||
MISession mi = getCSession().getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIVarCreate var = factory.createMIVarCreate(expressionId);
|
||||
try {
|
||||
mi.postCommand(var);
|
||||
MIVarCreateInfo info = var.getMIVarCreateInfo();
|
||||
MIChild child = info.getMIChild();
|
||||
cexp = new Expression(getCSession().getCTarget(), expressionId, child);
|
||||
expList.add(cexp);
|
||||
} catch (MIException e) {
|
||||
throw new CDIException(e.toString());
|
||||
public void removeVariables(ICDIVariable[] variables) throws CDIException {
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
removeVariable(variables[i]);
|
||||
}
|
||||
return cexp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#createCondition(int, String)
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createVariable(String)
|
||||
*/
|
||||
public ICDIVariable createVariable(String name) throws CDIException {
|
||||
ICDITarget target = getCSession().getCurrentTarget();
|
||||
CThread thread = ((CTarget)target).getCurrentThread();
|
||||
StackFrame stack = thread.getCurrentStackFrame();
|
||||
return createVariable(stack, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createVariable(ICDIStackFrame, String)
|
||||
*/
|
||||
public ICDIVariable createVariable(ICDIStackFrame frame, String name) throws CDIException {
|
||||
if (frame instanceof StackFrame) {
|
||||
StackFrame stack = (StackFrame)frame;
|
||||
Element element = createElement(stack, name);
|
||||
Variable var = new Variable(stack, name, element.miVar);
|
||||
element.variable = var;
|
||||
addElement(element);
|
||||
return var;
|
||||
}
|
||||
throw new CDIException("Unknow stackframe");
|
||||
}
|
||||
|
||||
|
||||
ICDIArgument createArgument(StackFrame stack, String name) throws CDIException {
|
||||
Element element = createElement(stack, name);
|
||||
Variable carg = new Argument(stack, name,element.miVar);
|
||||
element.variable = carg;
|
||||
addElement(element);
|
||||
return (ICDIArgument)carg;
|
||||
}
|
||||
|
||||
ICDIExpression createExpression(StackFrame stack, String name) throws CDIException {
|
||||
Element element = createElement(stack, name);
|
||||
Variable cexp = new Expression(stack, name, element.miVar);
|
||||
element.variable = cexp;
|
||||
addElement(element);
|
||||
return (ICDIExpression)cexp;
|
||||
}
|
||||
|
||||
ICDIRegister createRegister(StackFrame stack, String name) throws CDIException {
|
||||
Element element = createElement(stack, "$" + name);
|
||||
Variable reg = new Register(stack, name, element.miVar);
|
||||
element.variable = reg;
|
||||
addElement(element);
|
||||
return (ICDIRegister)reg;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createCondition(int, String)
|
||||
*/
|
||||
public ICDICondition createCondition(int ignoreCount, String expression) {
|
||||
return new Condition(ignoreCount, expression);
|
||||
|
|
Loading…
Add table
Reference in a new issue