1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Variable manager in terms of MI Var Object.

This commit is contained in:
Alain Magloire 2002-08-21 04:00:21 +00:00
parent c6df90506c
commit 4c8ccddf38
9 changed files with 85 additions and 198 deletions

View file

@ -42,62 +42,17 @@ import org.eclipse.cdt.debug.mi.core.output.MIThreadSelectInfo;
*/
public class CTarget implements ICDITarget {
List threadList;
CSession session;
CThread dummyThread; // Dummy for non multi-thread programs.
CThread currentThread;
//CThread dummyThread = new CThread(this, 0); // Dummy for non multi-thread programs.
public CTarget(CSession s) {
session = s;
threadList = new ArrayList(1);
dummyThread = new CThread(this, 1);
currentThread = dummyThread;
threadList.add(dummyThread);
}
CSession getCSession() {
return session;
}
void addCThread(CThread cthread) {
threadList.add(cthread);
}
void removeCThread(CThread cthread) {
threadList.remove(cthread);
}
void setCurrentThread(int id) {
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) {
for (int i = 0; i < threadList.size(); i++) {
CThread cthread = (CThread)threadList.get(i);
if (cthread.getId() == id) {
return true;
}
}
return false;
}
CThread[] getCThreads() {
return (CThread[])threadList.toArray(new CThread[threadList.size()]);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#disconnect()
*/
@ -170,18 +125,15 @@ public class CTarget implements ICDITarget {
return new ICDISharedLibrary[0];
}
/**
*/
public CThread getCurrentThread() throws CDIException {
return currentThread;
}
/**
*/
public void setCurrentThread(CThread cthread) throws CDIException {
session.setCurrentTarget(this);
int id = cthread.getId();
session.setCurrentTarget(this);
// No need to set thread id 0, it is a dummy thread.
if (id == 0) {
return;
}
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIThreadSelect select = factory.createMIThreadSelect(id);
@ -192,13 +144,13 @@ public class CTarget implements ICDITarget {
} catch (MIException e) {
throw new CDIException(e.toString());
}
setCurrentThread(id);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getThreads()
*/
public ICDIThread[] getThreads() throws CDIException {
ICDIThread[] cdiThreads;
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIThreadListIds tids = factory.createMIThreadListIds();
@ -207,18 +159,18 @@ public class CTarget implements ICDITarget {
MIThreadListIdsInfo info = tids.getMIThreadListIdsInfo();
int[] ids = info.getThreadIds();
if (ids != null && ids.length > 0) {
cdiThreads = new ICDIThread[ids.length];
// Ok that means it is a multiThreaded, remove the dummy Thread
//removeCThread(dummyThread);
for (int i = 0; i < ids.length; i++) {
if (! containsCThread(ids[i])) {
addCThread(new CThread(this, ids[i]));
}
cdiThreads[i] = new CThread(this, ids[i]);
}
} else {
cdiThreads = new ICDIThread[]{new CThread(this, 0)};
}
} catch (MIException e) {
throw new CDIException(e.toString());
}
return (ICDIThread[])getCThreads();
return cdiThreads;
}
/**
@ -437,9 +389,7 @@ public class CTarget implements ICDITarget {
*/
public ICDIValue evaluateExpressionToValue(String expressionText)
throws CDIException {
VariableManager mgr = session.getVariableManager();
ICDIVariable var = mgr.createVariable(expressionText);
return var.getValue();
return null;
}
/**

View file

@ -17,7 +17,6 @@ import org.eclipse.cdt.debug.mi.core.output.MIStackListFramesInfo;
public class CThread extends CObject implements ICDIThread {
int id;
StackFrame currentStackFrame;
public CThread(CTarget target, int threadId) {
super(target);
@ -56,9 +55,6 @@ public class CThread extends CObject implements ICDIThread {
StackFrame[] stack = new StackFrame[miFrames.length];
for (int i = 0; i < stack.length; i++) {
stack[i] = new StackFrame(this, miFrames[i]);
if (i == 0) {
currentStackFrame = stack[i];
}
}
return stack;
} catch (MIException e) {
@ -81,18 +77,11 @@ public class CThread extends CObject implements ICDIThread {
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()
*/

View file

@ -2,7 +2,6 @@ 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
@ -15,18 +14,18 @@ import org.eclipse.cdt.debug.mi.core.event.MIEvent;
public class ChangedEvent implements ICDIChangedEvent {
CSession session;
MIEvent event;
ICDIObject source;
public ChangedEvent(CSession s, MIEvent e) {
public ChangedEvent(CSession s, ICDIObject src) {
session = s;
event = e;
source = src;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEvent#getSource()
*/
public ICDIObject getSource() {
return null;
return source;
}
}

View file

@ -2,7 +2,6 @@ package org.eclipse.cdt.debug.mi.core.cdi;
import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent;
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
import org.eclipse.cdt.debug.mi.core.event.MIExitEvent;
/**
* @author alain
@ -14,19 +13,19 @@ import org.eclipse.cdt.debug.mi.core.event.MIExitEvent;
*/
public class DestroyedEvent implements ICDIDestroyedEvent {
MIExitEvent event;
CSession session;
ICDIObject source;
public DestroyedEvent(CSession s, MIExitEvent e) {
public DestroyedEvent(CSession s, ICDIObject src) {
session = s;
event = e;
source = src;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.event.ICDIEvent#getSource()
*/
public ICDIObject getSource() {
return null;
return source;
}
}

View file

@ -43,40 +43,40 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
if (miEvent instanceof MIBreakpointEvent) {
MIBreakpointEvent breakEvent = (MIBreakpointEvent)miEvent;
threadId = breakEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = breakEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MIFunctionFinishedEvent) {
MIFunctionFinishedEvent funcEvent = (MIFunctionFinishedEvent)miEvent;
threadId = funcEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = funcEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MILocationReachedEvent) {
MILocationReachedEvent locEvent = (MILocationReachedEvent)miEvent;
threadId = locEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = locEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MISignalEvent) {
MISignalEvent sigEvent = (MISignalEvent)miEvent;
threadId = sigEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = sigEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MISteppingRangeEvent) {
MISteppingRangeEvent rangeEvent = (MISteppingRangeEvent)miEvent;
threadId = rangeEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = rangeEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MIWatchpointEvent) {
MIWatchpointEvent watchEvent = (MIWatchpointEvent)miEvent;
threadId = watchEvent.getThreadId();
session.getCTarget().setCurrentThread(threadId);
//threadId = watchEvent.getThreadId();
//session.getCTarget().setCurrentThreadId(threadId);
cdiEvent = new SuspendedEvent(session, miEvent);
} else if (miEvent instanceof MIRunningEvent) {
cdiEvent = new ResumedEvent(session, (MIRunningEvent)miEvent);
} else if (miEvent instanceof MIInferiorExitEvent) {
cdiEvent = new ExitedEvent(session, (MIInferiorExitEvent)miEvent);
} else if (miEvent instanceof MIExitEvent) {
cdiEvent = new DestroyedEvent(session, (MIExitEvent)miEvent);
cdiEvent = new DestroyedEvent(session, null);
}
// Fire the event;

View file

@ -6,12 +6,6 @@ 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 {
@ -23,7 +17,7 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createCondition(int, String)
*/
public ICDICondition createCondition(int ignoreCount, String expression) {
return null;
return new Condition(ignoreCount, expression);
}
/**
@ -37,21 +31,19 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getExpressions()
*/
public ICDIExpression[] getExpressions() throws CDIException {
return null;
return new ICDIExpression[0];
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression)
*/
public void removeExpression(ICDIExpression expression)
throws CDIException {
public void removeExpression(ICDIExpression expression) throws CDIException {
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpressions(ICDIExpression[])
*/
public void removeExpressions(ICDIExpression[] expressions)
throws CDIException {
public void removeExpressions(ICDIExpression[] expressions) throws CDIException {
}
}

View file

@ -1,11 +1,10 @@
package org.eclipse.cdt.debug.mi.core.cdi;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpoint;
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager;
import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent;
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
import org.eclipse.cdt.debug.mi.core.event.MIBreakpointEvent;
import org.eclipse.cdt.debug.mi.core.event.MIEvent;
import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent;
@ -13,7 +12,6 @@ import org.eclipse.cdt.debug.mi.core.event.MILocationReachedEvent;
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
import org.eclipse.cdt.debug.mi.core.event.MISteppingRangeEvent;
import org.eclipse.cdt.debug.mi.core.event.MIWatchpointEvent;
import org.eclipse.cdt.debug.mi.core.output.MIBreakPoint;
/**
*
@ -79,16 +77,17 @@ public class SuspendedEvent implements ICDISuspendedEvent {
threadId = funcEvent.getThreadId();
}
// If it came from a thread return it as the source.
CThread[] cthreads = target.getCThreads();
for (int i = 0; i < cthreads.length; i++) {
if (cthreads[i].getId() == threadId) {
return cthreads[i];
try {
// If it came from a thread return it as the source.
ICDIThread[] cthreads = target.getThreads();
for (int i = 0; i < cthreads.length; i++) {
if (((CThread)cthreads[i]).getId() == threadId) {
return cthreads[i];
}
}
} catch (CDIException e) {
}
// Not found?? new thread created?
CThread cthread = new CThread(session.getCTarget(), threadId);
target.addCThread(cthread);
return cthread;
return null;
}
}

View file

@ -55,7 +55,7 @@ public class Value extends CObject implements ICDIValue {
}
result = info.getValue();
} catch (MIException e) {
throw new CDIException(e.toString());
//throw new CDIException(e.toString());
}
return result;
}
@ -84,7 +84,7 @@ public class Value extends CObject implements ICDIValue {
new Variable(variable.getStackFrame(), vars[i].getExp(), vars[i]);
}
} catch (MIException e) {
throw new CDIException(e.toString());
//throw new CDIException(e.toString());
}
return variables;
}

View file

@ -52,6 +52,16 @@ public class VariableManager extends SessionObject {
elementList = new ArrayList();
}
Element getElement(String varName) {
Element[] elements = getElements();
for (int i = 0; i < elements.length; i++) {
if (elements[i].miVar.getVarName().equals(varName)) {
return elements[i];
}
}
return null;
}
Element getElement(StackFrame stack, String name) {
Element[] elements = getElements();
for (int i = 0; i < elements.length; i++) {
@ -91,22 +101,27 @@ public class VariableManager extends SessionObject {
}
MIVarChange[]changes = info.getMIVarChanges();
for (int i = 0 ; i < changes.length; i++) {
ICDIEvent cdiEvent;
ICDIEvent cdiEvent = null;
Element element = getElement(changes[i].getVarName());
if (!changes[i].isInScope()) {
//cdiEvent = DestroyEvent(getCSession(), );
if (element != null) {
cdiEvent = new DestroyedEvent(getCSession(), element.variable);
}
removeVariable(changes[i]);
} else {
//cdiEvent = ChangedEvent(getCSession(), );
if (element != null) {
cdiEvent = new ChangedEvent(getCSession(), element.variable);
}
}
//EventManager mgr = (EventManager)getCSession().getEventManager();
//mgr.fireEvent(cdiEvent);
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 createElement(StackFrame stack, String name) throws CDIException {
Element element = getElement(stack, name);
if (element == null) {
stack.getCThread().setCurrentStackFrame(stack);
@ -130,31 +145,6 @@ public class VariableManager extends SessionObject {
return element;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getVariable(String)
*/
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.ICDIExpressionManager#getVariables()
*/
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;
}
void removeMIVar(MIVar miVar) throws CDIException {
MISession mi = getCSession().getMISession();
CommandFactory factory = mi.getCommandFactory();
@ -167,6 +157,11 @@ public class VariableManager extends SessionObject {
}
}
void removeVariable(MIVarChange changed) throws CDIException {
String varName = changed.getVarName();
removeVariable(varName);
}
void removeVariable(String varName) throws CDIException {
Element[] elements = getElements();
for (int i = 0; i < elements.length; i++) {
@ -177,53 +172,23 @@ public class VariableManager extends SessionObject {
}
}
void removeVariable(MIVarChange changed) throws CDIException {
String varName = changed.getVarName();
void removeVariable(Variable variable) throws CDIException {
String varName = ((Variable)variable).getMIVar().getVarName();
removeVariable(varName);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeVariable(ICDIVariable)
*/
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.ICDIExpressionManager#removeVariable(ICDIVariable[])
*/
public void removeVariables(ICDIVariable[] variables) throws CDIException {
void removeVariables(Variable[] variables) throws CDIException {
for (int i = 0; i < variables.length; i++) {
removeVariable(variables[i]);
}
}
/**
* @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");
ICDIVariable createVariable(StackFrame stack, String name) throws CDIException {
Element element = createElement(stack, name);
Variable var = new Variable(stack, name, element.miVar);
element.variable = var;
addElement(element);
return (ICDIVariable)var;
}
@ -250,11 +215,5 @@ public class VariableManager extends SessionObject {
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);
}
}