1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Rename of CTarget to Target

CSession to session
CThread to Thread.
This commit is contained in:
Alain Magloire 2003-01-27 03:22:04 +00:00
parent 8e125546ce
commit 4a1e38ac3a
42 changed files with 1452 additions and 834 deletions

View file

@ -1,3 +1,70 @@
2003-01-26 Alain Magloire
Major refactor of the code. Rewrote/Added Managers:
VariableManager
ExpressionManager
RegisterManager
UpdateManager.
Refactor of CSession to Session, CTarget to Target
and CThread to Thread.
* src/.../mi/core/cdi/event/ChangedEvent.java:
* src/.../mi/core/cdi/event/CreatedEvent.java:
* src/.../mi/core/cdi/event/DestroyedEvent.java:
* src/.../mi/core/cdi/event/DisconnectedEvent.java:
* src/.../mi/core/cdi/event/ExitedEvent.java:
* src/.../mi/core/cdi/event/MemoryChangedEvent.java:
* src/.../mi/core/cdi/event/ResumedEvent.java:
* src/.../mi/core/cdi/event/SuspendedEvent.java:
* src/.../mi/core/cdi/model/Argument.java:
* src/.../mi/core/cdi/model/Breakpoint.java:
* src/.../mi/core/cdi/model/Thread.java:
* src/.../mi/core/cdi/model/Target.java:
* src/.../mi/core/cdi/model/MemoryBlock.java:
* src/.../mi/core/cdi/model/MixedInstruction.java:
* src/.../mi/core/cdi/model/Instruction.java:
* src/.../mi/core/cdi/model/Signal.java:
* src/.../mi/core/cdi/model/SharedLibrary.java:
* src/.../mi/core/cdi/model/CObject.java:
* src/.../mi/core/cdi/model/Expression.java:
* src/.../mi/core/cdi/model/Variable.java:
* src/.../mi/core/cdi/model/Value.java:
* src/.../mi/core/cdi/model/Register.java:
* src/.../mi/core/cdi/model/StackFrame.java:
* src/.../mi/core/cdi/ArgumentObject.java:
* src/.../mi/core/cdi/VariableObject.java:
* src/.../mi/core/cdi/RegisterObject.java:
* src/.../mi/core/cdi/BreakpointHit.java:
* src/.../mi/core/cdi/BreakpointManager.java:
* src/.../mi/core/cdi/VariableManager.java:
* src/.../mi/core/cdi/ExpressionManager.java:
* src/.../mi/core/cdi/RegisterManaget.java:
* src/.../mi/core/cdi/SignalManager.java:
* src/.../mi/core/cdi/SharedLibraryManager.java:
* src/.../mi/core/cdi/EventManager.java:
* src/.../mi/core/cdi/MemoryManager.java:
* src/.../mi/core/cdi/ErrorInfo.java:
* src/.../mi/core/cdi/Session.java:
* src/.../mi/core/cdi/ExitInfo.java:
* src/.../mi/core/cdi/UpdateManager.java:
* src/.../mi/core/cdi/IUpdateListener.java:
* src/.../mi/core/cdi/SessionObject.java:
* src/.../mi/core/cdi/SignalReceived.java:
* src/.../mi/core/cdi/SourceManager.java:
* src/.../mi/core/cdi/RuntimeOptions.java:
* src/.../mi/core/cdi/WatchpointScope.java:
* src/.../mi/core/cdi/WatchpointTrigger.java:
* src/.../mi/core/cdi/EndSteppingRange.java:
* src/.../mi/core/MIPlugin.java:
* src/.../mi/core/CygwinGDBDebugger.java:
* src/.../mi/core/GDBDebugger.java:
2003-01-24 Alain Magloire
* src/.../mi/core/CLIProcessor.java (isEnableBreakpoint):

View file

@ -7,7 +7,7 @@ package org.eclipse.cdt.debug.mi.core;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.mi.core.cdi.CSession;
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.CygwinCommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIGDBSet;
@ -26,14 +26,14 @@ public class CygwinGDBDebugger extends GDBDebugger {
new CygwinCommandFactory();
/* Cygwin does not have any special initialization like solib paths etc.. */
protected void initializeLibraries(ILaunchConfiguration config, CSession session) throws CDIException {
protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CDIException {
}
public ICDISession createLaunchSession(
ILaunchConfiguration config,
IFile exe)
throws CDIException {
CSession session = (CSession) super.createLaunchSession(config, exe);
Session session = (Session) super.createLaunchSession(config, exe);
session.getMISession().setCommandFactory(commandFactory);
// For windows we need to start the inferior in a new console window
// to separate the Inferior std{in,out,err} from gdb std{in,out,err}
@ -58,8 +58,8 @@ public class CygwinGDBDebugger extends GDBDebugger {
IFile exe,
int pid)
throws CDIException {
CSession session =
(CSession) super.createAttachSession(config, exe, pid);
Session session =
(Session) super.createAttachSession(config, exe, pid);
session.getMISession().setCommandFactory(commandFactory);
return session;
}
@ -69,8 +69,8 @@ public class CygwinGDBDebugger extends GDBDebugger {
IFile exe,
IPath corefile)
throws CDIException {
CSession session =
(CSession) super.createCoreSession(config, exe, corefile);
Session session =
(Session) super.createCoreSession(config, exe, corefile);
session.getMISession().setCommandFactory(commandFactory);
return session;
}

View file

@ -12,7 +12,7 @@ import java.util.List;
import org.eclipse.cdt.debug.core.ICDebugger;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.mi.core.cdi.CSession;
import org.eclipse.cdt.debug.mi.core.cdi.Session;
import org.eclipse.cdt.debug.mi.core.cdi.SourceManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@ -21,7 +21,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
public class GDBDebugger implements ICDebugger {
protected void initializeLibraries(ILaunchConfiguration config, CSession session) throws CDIException {
protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CDIException {
try {
SourceManager mgr = (SourceManager)session.getSourceManager();
boolean autolib = config.getAttribute(IMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, true);
@ -41,7 +41,7 @@ public class GDBDebugger implements ICDebugger {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit);
Session session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
@ -58,7 +58,7 @@ public class GDBDebugger implements ICDebugger {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit);
Session session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
@ -76,7 +76,7 @@ public class GDBDebugger implements ICDebugger {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit);
Session session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit);
initializeLibraries(config, session);
return session;
} catch (IOException e) {

View file

@ -8,7 +8,7 @@ import java.io.File;
import java.io.IOException;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.mi.core.cdi.CSession;
import org.eclipse.cdt.debug.mi.core.cdi.Session;
import org.eclipse.cdt.debug.mi.core.command.CLICommand;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MITargetAttach;
@ -144,7 +144,7 @@ public class MIPlugin extends Plugin {
// If an exception is thrown that means ok
// we did not attach to any target.
}
return new CSession(session, false);
return new Session(session, false);
}
/**
@ -171,7 +171,7 @@ public class MIPlugin extends Plugin {
}
Process pgdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(pgdb, null, MISession.CORE);
return new CSession(session);
return new Session(session);
}
/**
@ -216,7 +216,7 @@ public class MIPlugin extends Plugin {
}
//@@@ We have to manually set the suspended state when we attach
session.getMIInferior().setSuspended();
return new CSession(session, true);
return new Session(session, true);
}
/**

View file

@ -0,0 +1,20 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.cdi;
import org.eclipse.cdt.debug.core.cdi.ICDIArgumentObject;
import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame;
/**
*/
public class ArgumentObject extends VariableObject implements ICDIArgumentObject {
public ArgumentObject(String name, StackFrame frame, int pos, int depth) {
super(name, frame, pos, depth);
}
}

View file

@ -16,7 +16,7 @@ public class BreakpointHit extends SessionObject implements ICDIBreakpointHit {
MIBreakpointHitEvent breakEvent;
public BreakpointHit(CSession session, MIBreakpointHitEvent e) {
public BreakpointHit(Session session, MIBreakpointHitEvent e) {
super(session);
breakEvent = e;
}
@ -27,7 +27,7 @@ public class BreakpointHit extends SessionObject implements ICDIBreakpointHit {
public ICDIBreakpoint getBreakpoint() {
int number = breakEvent.getNumber();
// Ask the breakpointManager for the breakpoint
BreakpointManager mgr = (BreakpointManager)getCSession().getBreakpointManager();
BreakpointManager mgr = (BreakpointManager)getSession().getBreakpointManager();
// We need to return the same object as the breakpoint.
Breakpoint point = mgr.getBreakpoint(number);
// FIXME: if point == null ?? Create a new breakpoint ??

View file

@ -6,6 +6,7 @@
package org.eclipse.cdt.debug.mi.core.cdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
@ -16,11 +17,12 @@ import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
import org.eclipse.cdt.debug.core.cdi.model.ICDICatchpoint;
import org.eclipse.cdt.debug.core.cdi.model.ICDILocationBreakpoint;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint;
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.Breakpoint;
import org.eclipse.cdt.debug.mi.core.cdi.model.CTarget;
import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
import org.eclipse.cdt.debug.mi.core.cdi.model.Watchpoint;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIBreakAfter;
@ -47,18 +49,18 @@ import org.eclipse.cdt.debug.mi.core.output.MIInfo;
public class BreakpointManager extends SessionObject implements ICDIBreakpointManager {
List breakList;
List delList;
boolean allowInterrupt;
boolean autoupdate;
public BreakpointManager(CSession session) {
public BreakpointManager(Session session) {
super(session);
breakList = new ArrayList(1);
delList = new ArrayList(1);
breakList = Collections.synchronizedList(new ArrayList());
allowInterrupt = true;
autoupdate = false;
}
public MIBreakpoint[] getMIBreakpoints() throws CDIException {
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakList breakpointList = factory.createMIBreakList();
try {
@ -73,49 +75,6 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
}
}
void update() throws CDIException {
MIBreakpoint[] newMIBreakpoints = getMIBreakpoints();
List eventList = new ArrayList(newMIBreakpoints.length);
for (int i = 0; i < newMIBreakpoints.length; i++) {
int no = newMIBreakpoints[i].getNumber();
if (containsBreakpoint(no)) {
if (hasBreakpointChanged(newMIBreakpoints[i])) {
// Fire ChangedEvent
eventList.add(new MIBreakpointChangedEvent(no));
}
} else {
// add the new breakpoint and fire CreatedEvent
if (newMIBreakpoints[i].isWatchpoint()) {
breakList.add(new Watchpoint(this, newMIBreakpoints[i]));
} else {
breakList.add(new Breakpoint(this, newMIBreakpoints[i]));
}
eventList.add(new MIBreakpointCreatedEvent(no));
}
}
// Check if any breakpoint was removed.
Breakpoint[] oldBreakpoints = listBreakpoints();
for (int i = 0; i < oldBreakpoints.length; i++) {
boolean found = false;
int no = oldBreakpoints[i].getMIBreakpoint().getNumber();
for (int j = 0; j < newMIBreakpoints.length; j++) {
if (no == newMIBreakpoints[j].getNumber()) {
found = true;
break;
}
}
if (!found) {
// Fire destroyed Events.
breakList.remove(oldBreakpoints[i]);
delList.add(oldBreakpoints[i]);
eventList.add(new MIBreakpointDeletedEvent(no));
}
}
MISession mi = getCSession().getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
boolean containsBreakpoint(int number) {
return (getBreakpoint(number) != null);
}
@ -152,107 +111,43 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
}
Breakpoint[] listBreakpoints() {
return (Breakpoint[]) breakList.toArray(new Breakpoint[breakList.size()]);
return (Breakpoint[]) breakList.toArray(new Breakpoint[0]);
}
boolean suspendInferior() throws CDIException {
boolean shouldRestart = false;
CSession s = getCSession();
CTarget target = s.getCTarget();
Session s = (Session)getSession();
ICDITarget currentTarget = s.getCurrentTarget();
// Stop the program and disable events.
if (target.isRunning() && allowInterrupt) {
int lastToken = target.getLastExecutionToken();
shouldRestart = true;
((EventManager)s.getEventManager()).disableEventToken(lastToken);
target.suspend();
((EventManager)s.getEventManager()).enableEventToken(lastToken);
if (currentTarget instanceof Target) {
Target target = (Target)currentTarget;
if (target.isRunning() && allowInterrupt) {
int lastToken = target.getLastExecutionToken();
shouldRestart = true;
((EventManager)s.getEventManager()).disableEventToken(lastToken);
target.suspend();
((EventManager)s.getEventManager()).enableEventToken(lastToken);
}
}
return shouldRestart;
}
void resumeInferior(boolean shouldRestart) throws CDIException {
if (shouldRestart) {
CSession s = getCSession();
CTarget target = s.getCTarget();
Session s = (Session)getSession();
ICDITarget target = s.getCurrentTarget();
target.resume();
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#allowProgramInterruption()
*/
public void allowProgramInterruption(boolean e) {
allowInterrupt = e;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteAllBreakpoints()
*/
public void deleteAllBreakpoints() throws CDIException {
deleteBreakpoints(listBreakpoints());
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteBreakpoint(ICDIBreakpoint)
*/
public void deleteBreakpoint(ICDIBreakpoint breakpoint)
throws CDIException {
deleteBreakpoints(new ICDIBreakpoint[] { breakpoint });
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteBreakpoints(ICDIBreakpoint[])
*/
public void deleteBreakpoints(ICDIBreakpoint[] breakpoints) throws CDIException {
int[] numbers = new int[breakpoints.length];
for (int i = 0; i < numbers.length; i++) {
if (breakpoints[i] instanceof Breakpoint
&& breakList.contains(breakpoints[i])) {
numbers[i] =
((Breakpoint) breakpoints[i]).getMIBreakpoint().getNumber();
} else {
throw new CDIException("Not a CDT breakpoint");
}
}
boolean state = suspendInferior();
CSession s = getCSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakDelete breakDelete = factory.createMIBreakDelete(numbers);
try {
s.getMISession().postCommand(breakDelete);
MIInfo info = breakDelete.getMIInfo();
if (info == null) {
throw new CDIException("No answer");
}
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
resumeInferior(state);
}
List eventList = new ArrayList(breakpoints.length);
for (int i = 0; i < breakpoints.length; i++) {
breakList.remove(breakpoints[i]);
delList.add(breakpoints[i]);
int no = ((Breakpoint)breakpoints[i]).getMIBreakpoint().getNumber();
eventList.add(new MIBreakpointDeletedEvent(no));
}
MISession mi = s.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
public Breakpoint deleteBreakpoint (int no) {
Breakpoint point = null;
Breakpoint[] points = (Breakpoint[])delList.toArray(new Breakpoint[delList.size()]);
public void deleteBreakpoint (int no) {
Breakpoint[] points = listBreakpoints();
for (int i = 0; i < points.length; i++) {
if (points[i].getMIBreakpoint().getNumber() == no) {
delList.remove(points[i]);
point = points[i];
breakList.remove(points[i]);
break;
}
}
return point;
}
public void enableBreakpoint(ICDIBreakpoint breakpoint) throws CDIException {
@ -264,10 +159,9 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
throw new CDIException("Not a CDT breakpoint");
}
boolean state = suspendInferior();
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakEnable breakEnable =
factory.createMIBreakEnable(new int[] { number });
MIBreakEnable breakEnable = factory.createMIBreakEnable(new int[] { number });
try {
s.getMISession().postCommand(breakEnable);
MIInfo info = breakEnable.getMIInfo();
@ -295,7 +189,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
throw new CDIException("Not a CDT breakpoint");
}
boolean state = suspendInferior();
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakDisable breakDisable =
factory.createMIBreakDisable(new int[] { number });
@ -326,7 +220,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
}
boolean state = suspendInferior();
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
// reset the values to sane states.
@ -364,19 +258,123 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber()));
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#update()
*/
public void update() throws CDIException {
MIBreakpoint[] newMIBreakpoints = getMIBreakpoints();
List eventList = new ArrayList(newMIBreakpoints.length);
for (int i = 0; i < newMIBreakpoints.length; i++) {
int no = newMIBreakpoints[i].getNumber();
if (containsBreakpoint(no)) {
if (hasBreakpointChanged(newMIBreakpoints[i])) {
// Fire ChangedEvent
eventList.add(new MIBreakpointChangedEvent(no));
}
} else {
// add the new breakpoint and fire CreatedEvent
if (newMIBreakpoints[i].isWatchpoint()) {
breakList.add(new Watchpoint(this, newMIBreakpoints[i]));
} else {
breakList.add(new Breakpoint(this, newMIBreakpoints[i]));
}
eventList.add(new MIBreakpointCreatedEvent(no));
}
}
// Check if any breakpoint was removed.
Breakpoint[] oldBreakpoints = listBreakpoints();
for (int i = 0; i < oldBreakpoints.length; i++) {
boolean found = false;
int no = oldBreakpoints[i].getMIBreakpoint().getNumber();
for (int j = 0; j < newMIBreakpoints.length; j++) {
if (no == newMIBreakpoints[j].getNumber()) {
found = true;
break;
}
}
if (!found) {
// Fire destroyed Events.
eventList.add(new MIBreakpointDeletedEvent(no));
}
}
MISession mi = ((Session)getSession()).getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#allowProgramInterruption()
*/
public void allowProgramInterruption(boolean e) {
allowInterrupt = e;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteAllBreakpoints()
*/
public void deleteAllBreakpoints() throws CDIException {
deleteBreakpoints(listBreakpoints());
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteBreakpoint(ICDIBreakpoint)
*/
public void deleteBreakpoint(ICDIBreakpoint breakpoint) throws CDIException {
deleteBreakpoints(new ICDIBreakpoint[] { breakpoint });
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteBreakpoints(ICDIBreakpoint[])
*/
public void deleteBreakpoints(ICDIBreakpoint[] breakpoints) throws CDIException {
int[] numbers = new int[breakpoints.length];
for (int i = 0; i < numbers.length; i++) {
if (breakpoints[i] instanceof Breakpoint
&& breakList.contains(breakpoints[i])) {
numbers[i] =
((Breakpoint) breakpoints[i]).getMIBreakpoint().getNumber();
} else {
throw new CDIException("Not a CDT breakpoint");
}
}
boolean state = suspendInferior();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakDelete breakDelete = factory.createMIBreakDelete(numbers);
try {
s.getMISession().postCommand(breakDelete);
MIInfo info = breakDelete.getMIInfo();
if (info == null) {
throw new CDIException("No answer");
}
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
resumeInferior(state);
}
List eventList = new ArrayList(breakpoints.length);
for (int i = 0; i < breakpoints.length; i++) {
int no = ((Breakpoint)breakpoints[i]).getMIBreakpoint().getNumber();
eventList.add(new MIBreakpointDeletedEvent(no));
}
MISession mi = s.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#getBreakpoints()
*/
public ICDIBreakpoint[] getBreakpoints() throws CDIException {
update();
return (ICDIBreakpoint[]) listBreakpoints();
return (ICDIBreakpoint[]) breakList.toArray(new ICDIBreakpoint[0]);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#getBreakpoints()
*/
// public ICDIBreakpoint[] getBreakpoints() throws CDIException {
// CSession s = getCSession();
// Session s = getCSession();
// CommandFactory factory = s.getMISession().getCommandFactory();
// MIBreakList breakpointList = factory.createMIBreakList();
// try {
@ -443,7 +441,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
}
boolean state = suspendInferior();
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakInsert breakInsert =
factory.createMIBreakInsert( temporary, hardware, exprCond,
@ -483,7 +481,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
boolean read = ( !((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE) &&
(watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ );
boolean state = suspendInferior();
CSession s = getCSession();
Session s = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory();
MIBreakWatch breakWatch =
factory.createMIBreakWatch(access, read, expression);
@ -533,4 +531,18 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
return new Location(address);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
}

View file

@ -11,7 +11,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange;
*/
public class EndSteppingRange extends SessionObject implements ICDIEndSteppingRange {
public EndSteppingRange(CSession session) {
public EndSteppingRange(Session session) {
super(session);
}
}

View file

@ -9,7 +9,7 @@ public class ErrorInfo extends SessionObject implements ICDIErrorInfo {
MIErrorEvent event;
public ErrorInfo(CSession session, MIErrorEvent e) {
public ErrorInfo(Session session, MIErrorEvent e) {
super(session);
event = e;
}

View file

@ -12,9 +12,18 @@ import java.util.Observable;
import java.util.Observer;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager;
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.ICDISharedLibraryManager;
import org.eclipse.cdt.debug.core.cdi.ICDISignalManager;
import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.cdi.event.ChangedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.event.CreatedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.event.DestroyedEvent;
@ -23,8 +32,8 @@ import org.eclipse.cdt.debug.mi.core.cdi.event.ExitedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.event.MemoryChangedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.event.ResumedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.event.SuspendedEvent;
import org.eclipse.cdt.debug.mi.core.cdi.model.CTarget;
import org.eclipse.cdt.debug.mi.core.cdi.model.MemoryBlock;
import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
import org.eclipse.cdt.debug.mi.core.event.MIBreakpointChangedEvent;
import org.eclipse.cdt.debug.mi.core.event.MIBreakpointCreatedEvent;
import org.eclipse.cdt.debug.mi.core.event.MIBreakpointDeletedEvent;
@ -62,7 +71,7 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
*/
public void update(Observable o, Object arg) {
MIEvent miEvent = (MIEvent)arg;
CSession session = getCSession();
Session session = (Session)getSession();
List cdiList = new ArrayList(1);
if (ignoreEventToken(miEvent.getToken())) {
@ -168,7 +177,7 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
fireEvents(cdiEvents);
}
public EventManager(CSession session) {
public EventManager(Session session) {
super(session);
}
@ -217,22 +226,46 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
* fired for changes.
*/
void processSuspendedEvent(MIStoppedEvent stopped) {
CTarget target = getCSession().getCTarget();
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
// Set the current thread.
int threadId = threadId = stopped.getThreadId();
target.updateState(threadId);
if (currentTarget instanceof Target) {
((Target)currentTarget).updateState(threadId);
}
// Update the managers.
VariableManager varMgr = getCSession().getVariableManager();
RegisterManager regMgr = getCSession().getRegisterManager();
MemoryManager memMgr = (MemoryManager)getCSession().getMemoryManager();
SharedLibraryManager libMgr = (SharedLibraryManager)getCSession().getSharedLibraryManager();
// For the Variable/Expression Managers call only the updateManager.
UpdateManager upMgr = session.getUpdateManager();
ICDIVariableManager varMgr = session.getVariableManager();
ICDIExpressionManager expMgr = session.getExpressionManager();
ICDIRegisterManager regMgr = session.getRegisterManager();
ICDIMemoryManager memMgr = session.getMemoryManager();
ICDISharedLibraryManager libMgr = session.getSharedLibraryManager();
ICDIBreakpointManager bpMgr = session.getBreakpointManager();
ICDISignalManager sigMgr = session.getSignalManager();
ICDISourceManager srcMgr = session.getSourceManager();
try {
varMgr.update();
regMgr.update();
memMgr.update();
libMgr.update();
if (varMgr.isAutoUpdate() || expMgr.isAutoUpdate()) {
upMgr.update();
}
if (regMgr.isAutoUpdate()) {
regMgr.update();
}
if (memMgr.isAutoUpdate()) {
memMgr.update();
}
if (libMgr.isAutoUpdate()) {
libMgr.update();
}
if (bpMgr.isAutoUpdate()) {
bpMgr.update();
}
if (sigMgr.isAutoUpdate()) {
sigMgr.update();
}
if (srcMgr.isAutoUpdate()) {
srcMgr.update();
}
} catch (CDIException e) {
//System.out.println(e);
}
@ -242,7 +275,7 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs
* Do any processing of before a running event.
*/
void processRunningEvent() {
//CTarget target = getCSession().getCTarget();
//Target target = getCSession().getCTarget();
//target.clearState();
}

View file

@ -14,7 +14,7 @@ public class ExitInfo extends SessionObject implements ICDIExitInfo {
MIInferiorExitEvent event;
public ExitInfo(CSession session, MIInferiorExitEvent e) {
public ExitInfo(Session session, MIInferiorExitEvent e) {
super(session);
event = e;
}

View file

@ -0,0 +1,179 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.cdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.StackFrame;
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.event.MIEvent;
import org.eclipse.cdt.debug.mi.core.event.MIVarChangedEvent;
import org.eclipse.cdt.debug.mi.core.output.MIVarChange;
import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo;
/**
*/
public class ExpressionManager extends SessionObject implements ICDIExpressionManager, IUpdateListener {
private List expList;
private boolean autoupdate;
public ExpressionManager(Session session) {
super(session);
expList = Collections.synchronizedList(new ArrayList());
autoupdate = true;
}
synchronized private void addExpression(Expression exp) {
expList.add(exp);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(String)
*/
public ICDIExpression createExpression(String name) throws CDIException {
Expression expression = null;
try {
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarCreate var = factory.createMIVarCreate(name);
mi.postCommand(var);
MIVarCreateInfo info = var.getMIVarCreateInfo();
if (info == null) {
throw new CDIException("No answer");
}
VariableObject varObj = new VariableObject(name, null, 0, 0);
expression = new Expression(varObj, info.getMIVar());
addExpression(expression);
} catch (MIException e) {
throw new MI2CDIException(e);
}
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;
if (!(frame instanceof StackFrame)) {
return expression;
}
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread();
ICDIStackFrame currentFrame = currentThread.getCurrentStackFrame();
frame.getThread().setCurrentStackFrame(frame);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarCreate var = factory.createMIVarCreate(name);
mi.postCommand(var);
MIVarCreateInfo info = var.getMIVarCreateInfo();
if (info == null) {
throw new CDIException("No answer");
}
VariableObject varObj = new VariableObject(name, (StackFrame)frame, 0, 0);
expression = new Expression(varObj, info.getMIVar());
addExpression(expression);
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
currentThread.setCurrentStackFrame(currentFrame);
}
return expression;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getExpressions()
*/
public ICDIExpression[] getExpressions() throws CDIException {
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);
}
/**
* Return the element that have the uniq varName.
* null is return if the element is not in the cache.
*/
public Expression 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];
}
}
return null;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#update()
*/
public void update() throws CDIException {
Session session = (Session)getSession();
UpdateManager mgr = session.getUpdateManager();
mgr.update();
}
/**
* @see org.eclipse.cdt.debug.mi.core.cdi.IUpdateListener#changeList(MIVarChange[])
*/
public void changeList(MIVarChange[] changes) {
List eventList = new ArrayList(changes.length);
for (int i = 0 ; i < changes.length; i++) {
String varName = changes[i].getVarName();
Expression expression = getExpression(varName);
if (expression != null) {
eventList.add(new MIVarChangedEvent(0, varName, changes[i].isInScope()));
}
}
Session session = (Session)getSession();
MISession mi = session.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
}

View file

@ -0,0 +1,12 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.cdi;
import org.eclipse.cdt.debug.mi.core.output.MIVarChange;
public interface IUpdateListener {
void changeList(MIVarChange[] changes);
}

View file

@ -27,10 +27,12 @@ import org.eclipse.cdt.debug.mi.core.output.MIDataReadMemoryInfo;
public class MemoryManager extends SessionObject implements ICDIMemoryManager {
List blockList;
boolean autoupdate;
public MemoryManager(CSession session) {
public MemoryManager(Session session) {
super(session);
blockList = new ArrayList();
autoupdate = true;
}
/**
@ -38,9 +40,12 @@ public class MemoryManager extends SessionObject implements ICDIMemoryManager {
* inferior comes to a Stop/Suspended. It will allow to look at the blocks that
* are registered and fired any event if changed.
* Note: Frozen blocks are not updated.
*
* @see org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager#createMemoryBlock(long, int)
*/
public void update() {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
MemoryBlock[] blocks = listMemoryBlocks();
List eventList = new ArrayList(blocks.length);
for (int i = 0; i < blocks.length; i++) {
@ -68,7 +73,8 @@ public class MemoryManager extends SessionObject implements ICDIMemoryManager {
if (aList != null) {
aList.add(new MIMemoryChangedEvent(array));
} else {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
mi.fireEvent(new MIMemoryChangedEvent(array));
}
}
@ -112,16 +118,18 @@ public class MemoryManager extends SessionObject implements ICDIMemoryManager {
* with the MemoryManager.
*/
MemoryBlock cloneBlock(MemoryBlock block) throws CDIException {
Session session = (Session)getSession();
String exp = block.getExpression();
MIDataReadMemoryInfo info = createMIDataReadMemoryInfo(exp, (int)block.getLength());
return new MemoryBlock(getCSession().getCTarget(), exp, info);
return new MemoryBlock(session.getCurrentTarget(), exp, info);
}
/**
* Post a -data-read-memory to gdb/mi.
*/
MIDataReadMemoryInfo createMIDataReadMemoryInfo(String exp, int length) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIDataReadMemory mem = factory.createMIDataReadMemory(0, exp, MIFormat.HEXADECIMAL, 1, 1, length, null);
try {
@ -149,10 +157,11 @@ public class MemoryManager extends SessionObject implements ICDIMemoryManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager#createMemoryBlock(string, int)
*/
public ICDIMemoryBlock createMemoryBlock(String address, int length) throws CDIException {
Session session = (Session)getSession();
MIDataReadMemoryInfo info = createMIDataReadMemoryInfo(address, length);
ICDIMemoryBlock block = new MemoryBlock(getCSession().getCTarget(), address, info);
ICDIMemoryBlock block = new MemoryBlock(session.getCurrentTarget(), address, info);
blockList.add(block);
MISession mi = getCSession().getMISession();
MISession mi = session.getMISession();
mi.fireEvent(new MIMemoryCreatedEvent(block.getStartAddress(), block.getLength()));
return block;
}
@ -188,4 +197,18 @@ public class MemoryManager extends SessionObject implements ICDIMemoryManager {
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIMemoryManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
}

View file

@ -6,10 +6,13 @@
package org.eclipse.cdt.debug.mi.core.cdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager;
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
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.Register;
@ -24,20 +27,23 @@ import org.eclipse.cdt.debug.mi.core.output.MIDataListRegisterNamesInfo;
/**
*/
public class RegisterManager extends SessionObject {
public class RegisterManager extends SessionObject implements ICDIRegisterManager {
List regList;
private List regList;
private boolean autoupdate;
public RegisterManager(CSession session) {
public RegisterManager(Session session) {
super(session);
regList = new ArrayList();
regList = Collections.synchronizedList(new ArrayList());
autoupdate = true;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getRegisterObjects()
*/
public ICDIRegisterObject[] getRegisterObjects() throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIDataListRegisterNames registers = factory.createMIDataListRegisterNames();
try {
@ -58,10 +64,45 @@ public class RegisterManager extends SessionObject {
}
}
Register[] getRegisters() {
return (Register[])regList.toArray(new Register[0]);
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#createRegister()
*/
public ICDIRegister createRegister(ICDIRegisterObject regObject) throws CDIException {
Register reg = getRegister(regObject);
if (reg == null) {
Session session = (Session)getSession();
reg = new Register(session.getCurrentTarget(), regObject);
regList.add(reg);
MISession mi = session.getMISession();
mi.fireEvent(new MIRegisterCreatedEvent(reg.getName(), reg.getID()));
}
return reg;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager#destroyRegister(ICDIRegister)
*/
public void destroyRegister(ICDIRegister reg) {
regList.remove(reg);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* Use by the eventManager to find the Register;
*/
public Register getRegister(int regno) throws CDIException {
Register[] regs = getRegisters();
for (int i = 0; i < regs.length; i++) {
@ -72,37 +113,12 @@ public class RegisterManager extends SessionObject {
return null;
}
Register getRegister(ICDIRegisterObject regObject) throws CDIException {
Register[] regs = getRegisters();
for (int i = 0; i < regs.length; i++) {
if (regObject.getName().equals(regs[i].getName())) {
return regs[i];
}
}
return null;
}
public Register createRegister(ICDIRegisterObject regObject) throws CDIException {
Register reg = getRegister(regObject);
if (reg == null) {
reg = new Register(getCSession().getCTarget(), regObject);
regList.add(reg);
MISession mi = getCSession().getMISession();
mi.fireEvent(new MIRegisterCreatedEvent(reg.getName(), reg.getID()));
}
return reg;
}
Register[] createRegisters(ICDIRegisterObject[] regObjects) throws CDIException {
Register[] regs = new Register[regObjects.length];
for (int i = 0; i < regs.length; i++) {
regs[i] = createRegister(regObjects[i]);
}
return regs;
}
/**
* Call the by the EventManager when the target is suspended.
*/
public void update() throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIDataListChangedRegisters changed = factory.createMIDataListChangedRegisters();
try {
@ -127,4 +143,19 @@ public class RegisterManager extends SessionObject {
}
}
private Register[] getRegisters() {
return (Register[])regList.toArray(new Register[0]);
}
private Register getRegister(ICDIRegisterObject regObject) throws CDIException {
Register[] regs = getRegisters();
for (int i = 0; i < regs.length; i++) {
if (regObject.getName().equals(regs[i].getName())) {
return regs[i];
}
}
return null;
}
}

View file

@ -4,25 +4,10 @@ import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject;
/**
*/
public class RegisterObject implements ICDIRegisterObject {
public class RegisterObject extends VariableObject implements ICDIRegisterObject {
int index;
String name;
public RegisterObject(String n, int i) {
name = n;
index = i;
}
public int getId() {
return index;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject#getName()
*/
public String getName() {
return name;
public RegisterObject(String name, int i) {
super(name, null, i, 0);
}
}

View file

@ -21,9 +21,9 @@ import org.eclipse.cdt.debug.mi.core.output.MIInfo;
*/
public class RuntimeOptions implements ICDIRuntimeOptions {
CSession session;
Session session;
public RuntimeOptions(CSession s) {
public RuntimeOptions(Session s) {
session = s;
}

View file

@ -14,28 +14,32 @@ 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.ICDIRuntimeOptions;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager;
import org.eclipse.cdt.debug.core.cdi.ICDISignalManager;
import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
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.CTarget;
import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession
*/
public class CSession implements ICDISession, ICDISessionObject {
public class Session implements ICDISession, ICDISessionObject {
Properties props;
MISession session;
BreakpointManager breakpointManager;
UpdateManager updateManager;
EventManager eventManager;
BreakpointManager breakpointManager;
ExpressionManager expressionManager;
VariableManager variableManager;
RegisterManager registerManager;
MemoryManager memoryManager;
@ -43,14 +47,14 @@ public class CSession implements ICDISession, ICDISessionObject {
SignalManager signalManager;
SourceManager sourceManager;
ICDIConfiguration configuration;
CTarget ctarget;
Target ctarget;
public CSession(MISession s, boolean attach) {
public Session(MISession s, boolean attach) {
commonSetup(s);
configuration = new Configuration(s, attach);
}
public CSession(MISession s) {
public Session(MISession s) {
commonSetup(s);
configuration = new CoreFileConfiguration();
}
@ -58,24 +62,32 @@ public class CSession implements ICDISession, ICDISessionObject {
private void commonSetup(MISession s) {
session = s;
props = new Properties();
breakpointManager = new BreakpointManager(this);
eventManager = new EventManager(this);
s.addObserver(eventManager);
updateManager = new UpdateManager(this);
expressionManager = new ExpressionManager(this);
variableManager = new VariableManager(this);
updateManager.addUpdateListener(variableManager);
updateManager.addUpdateListener(expressionManager);
registerManager = new RegisterManager(this);
memoryManager = new MemoryManager(this);
signalManager = new SignalManager(this);
sourceManager = new SourceManager(this);
sharedLibraryManager = new SharedLibraryManager(this);
ctarget = new CTarget(this);
ctarget = new Target(this);
}
public MISession getMISession() {
return session;
}
public CTarget getCTarget() {
return ctarget;
public UpdateManager getUpdateManager() {
return updateManager;
}
/**
@ -100,12 +112,26 @@ public class CSession implements ICDISession, ICDISessionObject {
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getVariableManager()
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getExpressionManager()
*/
public ICDIExpressionManager getExpressionManager() {
return expressionManager;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getVariableManager()
*/
public ICDIVariableManager getVariableManager() {
return variableManager;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getRegisterManager()
*/
public ICDIRegisterManager getRegisterManager() {
return registerManager;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getSharedLibraryManager()
*/
@ -113,18 +139,6 @@ public class CSession implements ICDISession, ICDISessionObject {
return sharedLibraryManager;
}
/**
*/
public RegisterManager getRegisterManager() {
return registerManager;
}
/**
*/
public VariableManager getVariableManager() {
return variableManager;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#getMemoryManager()
*/
@ -161,13 +175,14 @@ public class CSession implements ICDISession, ICDISessionObject {
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISession#setCurrentTarget()
*/
public void setCurrentTarget(ICDITarget target) throws CDIException {
if (target instanceof CTarget) {
ctarget = (CTarget)target;
return;
if (target instanceof Target) {
ctarget = (Target)target;
} else {
throw new CDIException("Unkown target");
}
throw new CDIException("Unkown target");
}
/**

View file

@ -12,9 +12,9 @@ import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
*/
public class SessionObject implements ICDISessionObject {
private CSession session;
private Session session;
public SessionObject (CSession session) {
public SessionObject (Session session) {
this.session = session;
}
@ -25,7 +25,4 @@ public class SessionObject implements ICDISessionObject {
return session;
}
public CSession getCSession() {
return session;
}
}

View file

@ -34,25 +34,30 @@ public class SharedLibraryManager extends SessionObject implements ICDISharedLib
List sharedList;
List unloadedList;
boolean autoupdate;
public SharedLibraryManager (CSession session) {
public SharedLibraryManager (Session session) {
super(session);
sharedList = new ArrayList(1);
unloadedList = new ArrayList(1);
autoupdate = true;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager#update()
*/
public void update() throws CDIException {
CSession s = getCSession();
ICDIConfiguration conf = s.getConfiguration();
Session session = (Session)getSession();
ICDIConfiguration conf = session.getConfiguration();
if (!conf.supportsSharedLibrary()) {
return; // Bail out early;
}
MIShared[] miLibs = new MIShared[0];
CommandFactory factory = s.getMISession().getCommandFactory();
CommandFactory factory = session.getMISession().getCommandFactory();
MIInfoSharedLibrary infoShared = factory.createMIInfoSharedLibrary();
try {
s.getMISession().postCommand(infoShared);
session.getMISession().postCommand(infoShared);
MIInfoSharedLibraryInfo info = infoShared.getMIInfoSharedLibraryInfo();
if (info == null) {
throw new CDIException("No answer");
@ -93,7 +98,7 @@ public class SharedLibraryManager extends SessionObject implements ICDISharedLib
eventList.add(new MISharedLibUnloadedEvent(oldlibs[i].getFileName()));
}
}
MISession mi = getCSession().getMISession();
MISession mi = session.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
@ -161,10 +166,10 @@ public class SharedLibraryManager extends SessionObject implements ICDISharedLib
* @see org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager#loadSymbols()
*/
public void loadSymbols() throws CDIException {
CSession s = getCSession();
Session session = (Session)getSession();
CLICommand cmd = new CLICommand("shared");
try {
s.getMISession().postCommand(cmd);
session.getMISession().postCommand(cmd);
MIInfo info = cmd.getMIInfo();
if (info == null) {
throw new CDIException("No answer");
@ -184,10 +189,10 @@ public class SharedLibraryManager extends SessionObject implements ICDISharedLib
if (libs[i].areSymbolsLoaded()) {
continue;
}
CSession s = getCSession();
Session session = (Session)getSession();
CLICommand cmd = new CLICommand("shared " + libs[i].getFileName());
try {
s.getMISession().postCommand(cmd);
session.getMISession().postCommand(cmd);
MIInfo info = cmd.getMIInfo();
if (info == null) {
throw new CDIException("No answer");
@ -199,4 +204,18 @@ public class SharedLibraryManager extends SessionObject implements ICDISharedLib
update();
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
}

View file

@ -13,8 +13,11 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDISignal;
*/
public class SignalManager extends SessionObject implements ICDISignalManager {
public SignalManager(CSession session) {
boolean autoupdate;
public SignalManager(Session session) {
super(session);
autoupdate = false;
}
/**
@ -24,4 +27,24 @@ public class SignalManager extends SessionObject implements ICDISignalManager {
return new ICDISignal[0];
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISignalManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISignalManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISignalManager#update()
*/
public void update() throws CDIException {
}
}

View file

@ -16,9 +16,9 @@ import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
public class SignalReceived extends SessionObject implements ICDISignalReceived {
ICDISignal signal;
public SignalReceived(CSession session, MISignalEvent event) {
public SignalReceived(Session session, MISignalEvent event) {
super(session);
signal = new Signal(session.getCTarget(), event);
signal = new Signal(session.getCurrentTarget(), event);
}
/**

View file

@ -31,15 +31,19 @@ import org.eclipse.cdt.debug.mi.core.output.MISrcAsm;
*/
public class SourceManager extends SessionObject implements ICDISourceManager {
public SourceManager(CSession session) {
boolean autoupdate;
public SourceManager(Session session) {
super(session);
autoupdate = false;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#addSourcePaths(String[])
*/
public void addSourcePaths(String[] dirs) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIEnvironmentDirectory dir = factory.createMIEnvironmentDirectory(dirs);
try {
@ -54,7 +58,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getSourcePaths()
*/
public String[] getSourcePaths() throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBShowDirectories dir = factory.createMIGDBShowDirectories();
try {
@ -67,7 +72,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
}
public void setLibraryPaths(String[] libPaths) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBSetSolibSearchPath solib = factory.createMIGDBSetSolibSearchPath(libPaths);
try {
@ -79,7 +85,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
}
public String[] getLibraryPaths() throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBShowSolibSearchPath dir = factory.createMIGDBShowSolibSearchPath();
try {
@ -92,7 +99,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
}
public void setAutoSolib(boolean set) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBSetAutoSolib solib = factory.createMIGDBSetAutoSolib(set);
try {
@ -107,7 +115,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getInstructions(String, int, int)
*/
public ICDIInstruction[] getInstructions(String filename, int linenum, int lines) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIDataDisassemble dis = factory.createMIDataDisassemble(filename, linenum, lines, false);
try {
@ -116,7 +125,7 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
MIAsm[] asm = info.getMIAsms();
Instruction[] instructions = new Instruction[asm.length];
for (int i = 0; i < instructions.length; i++) {
instructions[i] = new Instruction(getCSession().getCTarget(), asm[i]);
instructions[i] = new Instruction(session.getCurrentTarget(), asm[i]);
}
return instructions;
} catch (MIException e) {
@ -135,7 +144,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getInstructions(long, long)
*/
public ICDIInstruction[] getInstructions(long start, long end) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
String hex = "0x";
String sa = hex + Long.toHexString(start);
@ -147,7 +157,7 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
MIAsm[] asm = info.getMIAsms();
Instruction[] instructions = new Instruction[asm.length];
for (int i = 0; i < instructions.length; i++) {
instructions[i] = new Instruction(getCSession().getCTarget(), asm[i]);
instructions[i] = new Instruction(session.getCurrentTarget(), asm[i]);
}
return instructions;
} catch (MIException e) {
@ -159,7 +169,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getMixedInstructions(String, int, int)
*/
public ICDIMixedInstruction[] getMixedInstructions(String filename, int linenum, int lines) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIDataDisassemble dis = factory.createMIDataDisassemble(filename, linenum, lines, true);
try {
@ -168,7 +179,7 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
MISrcAsm[] srcAsm = info.getMISrcAsms();
ICDIMixedInstruction[] mixed = new ICDIMixedInstruction[srcAsm.length];
for (int i = 0; i < mixed.length; i++) {
mixed[i] = new MixedInstruction(getCSession().getCTarget(), srcAsm[i]);
mixed[i] = new MixedInstruction(session.getCurrentTarget(), srcAsm[i]);
}
return mixed;
} catch (MIException e) {
@ -187,7 +198,8 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getMixedInstructions(long, long)
*/
public ICDIMixedInstruction[] getMixedInstructions(long start, long end) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
String hex = "0x";
String sa = hex + Long.toHexString(start);
@ -199,7 +211,7 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
MISrcAsm[] srcAsm = info.getMISrcAsms();
ICDIMixedInstruction[] mixed = new ICDIMixedInstruction[srcAsm.length];
for (int i = 0; i < mixed.length; i++) {
mixed[i] = new MixedInstruction(getCSession().getCTarget(), srcAsm[i]);
mixed[i] = new MixedInstruction(session.getCurrentTarget(), srcAsm[i]);
}
return mixed;
} catch (MIException e) {
@ -207,4 +219,24 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#update()
*/
public void update() throws CDIException {
}
}

View file

@ -0,0 +1,64 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.cdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
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.MIVarUpdate;
import org.eclipse.cdt.debug.mi.core.output.MIVarChange;
import org.eclipse.cdt.debug.mi.core.output.MIVarUpdateInfo;
/**
*/
public class UpdateManager {
Session session;
List updateList = Collections.synchronizedList(new ArrayList(5));
MIVarChange[] noChanges = new MIVarChange[0];
public UpdateManager(Session s) {
session = s;
}
public void addUpdateListener(IUpdateListener listener) {
updateList.add(listener);
}
public void removeUpdateListener(IUpdateListener listener) {
updateList.remove(listener);
}
/**
* Update the variables, from the response of the "-var-update *"
* mi/command.
*/
public void update() throws CDIException {
MIVarChange[] changes = noChanges;
MISession mi = session.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");
}
changes = info.getMIVarChanges();
} catch (MIException e) {
throw new MI2CDIException(e);
}
IUpdateListener[] listeners = (IUpdateListener[])updateList.toArray(new IUpdateListener[0]);
for (int i = 0; i < listeners.length; i++) {
listeners[i].changeList(changes);
}
}
}

View file

@ -6,90 +6,83 @@
package org.eclipse.cdt.debug.mi.core.cdi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
import org.eclipse.cdt.debug.core.cdi.ICDIArgumentObject;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableObject;
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.ICDIStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
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.cdi.model.Argument;
import org.eclipse.cdt.debug.mi.core.cdi.model.CTarget;
import org.eclipse.cdt.debug.mi.core.cdi.model.CThread;
import org.eclipse.cdt.debug.mi.core.cdi.model.Expression;
import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame;
import org.eclipse.cdt.debug.mi.core.cdi.model.Thread;
import org.eclipse.cdt.debug.mi.core.cdi.model.Variable;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIStackListArguments;
import org.eclipse.cdt.debug.mi.core.command.MIStackListLocals;
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.MIVarCreatedEvent;
import org.eclipse.cdt.debug.mi.core.output.MIArg;
import org.eclipse.cdt.debug.mi.core.output.MIFrame;
import org.eclipse.cdt.debug.mi.core.output.MIStackListArgumentsInfo;
import org.eclipse.cdt.debug.mi.core.output.MIStackListLocalsInfo;
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 VariableManager extends SessionObject implements ICDIExpressionManager {
public class VariableManager extends SessionObject implements ICDIVariableManager, IUpdateListener {
List elementList;
List oosList; // Out of Scope variable lists;
List variableList;
boolean autoupdate;
/**
* Class container to regroup all info concerning a variable.
*/
public class Element {
public MIVar miVar;
public String name;
public StackFrame stackframe;
public int stackdepth;
public Variable variable;
}
public VariableManager(CSession session) {
public VariableManager(Session session) {
super(session);
elementList = new ArrayList();
oosList = new ArrayList();
variableList = Collections.synchronizedList(new ArrayList());
autoupdate = true;
}
/**
* Return the element that have the uniq varName.
* null is return if the element is not in the cache.
*/
public 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];
public Variable getVariable(String varName) {
Variable[] vars = getVariables();
for (int i = 0; i < vars.length; i++) {
if (vars[i].getMIVar().getVarName().equals(varName)) {
return vars[i];
}
}
return null;
}
/**
* Return the Element with that stackframe, stack, that with this name.
* Return the Element with this stackframe, and with this name.
* null is return if the element is not in the cache.
*/
Element getElement(StackFrame stack, String name) {
Element[] elements = getElements();
for (int i = 0; i < elements.length; i++) {
if (elements[i].name.equals(name)) {
if (elements[i].stackframe.equals(stack)) {
int depth = 0;
CThread thread = stack.getCThread();
if (thread != null) {
try {
depth = thread.getStackFrameCount();
} catch (CDIException e) {
Variable findVariable(VariableObject v) throws CDIException {
ICDIStackFrame stack = v.getStackFrame();
String name = v.getName();
int position = v.getPosition();
int depth = v.getStackDepth();
Variable[] vars = getVariables();
for (int i = 0; i < vars.length; i++) {
if (vars[i].getName().equals(name)) {
if (vars[i].getStackFrame().equals(stack)) {
if (vars[i].getVariableObject().getPosition() == position) {
if (vars[i].getVariableObject().getStackDepth() == depth) {
return vars[i];
}
}
if (elements[i].stackdepth == depth) {
return elements[i];
}
}
}
}
@ -99,112 +92,36 @@ public class VariableManager extends SessionObject implements ICDIExpressionMana
/**
* Make sure an element is not added twice.
*/
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())) {
void addVariable(Variable var) {
Variable[] vars = getVariables();
for (int i = 0; i < vars.length; i++) {
String name = vars[i].getMIVar().getVarName();
if (name.equals(var.getMIVar().getVarName())) {
return;
}
}
elementList.add(element);
variableList.add(var);
}
/**
* Returns all the elements that are in the cache.
*/
Element[] getElements() {
return (Element[]) elementList.toArray(new Element[0]);
Variable[] getVariables() {
return (Variable[]) variableList.toArray(new Variable[0]);
}
/**
* Update the elements in the cache, from the response of the "-var-update *"
* mi/command. Out-of-scope elements are removed etc ..
* Expression are special they are not remove when out-of-scope is thrown.
* For all remove element in the cache fires a destroy event.
*/
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();
List eventList = new ArrayList(changes.length);
for (int i = 0 ; i < changes.length; i++) {
String varName = changes[i].getVarName();
Element element = getElement(varName);
if (element != null) {
eventList.add(new MIVarChangedEvent(update.getToken(), varName, changes[i].isInScope()));
}
if (! changes[i].isInScope()) {
// Only remove ICDIVariables.
if (! (element.variable instanceof Expression)) {
removeElement(changes[i]);
}
}
}
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
} catch (MIException e) {
throw new MI2CDIException(e);
}
}
/**
* If element is not in the cache create a new element "-var-create"
* for the stackframe(stack).
*/
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;
CThread thread = stack.getCThread();
if (thread != null) {
element.stackdepth = thread.getStackFrameCount();
}
} catch (MIException e) {
throw new MI2CDIException(e);
}
}
return element;
}
/**
* Remove element from the OutOfscope list(oos).
*/
public Element removeOutOfScope(String varName) {
Element[] oos = (Element[])oosList.toArray(new Element[0]);
for (int i = 0; i < oos.length; i++) {
if (oos[i].miVar.getVarName().equals(varName)) {
return oos[i];
}
}
return null;
public Variable createVariable(VariableObject v, MIVar mivar) throws CDIException {
Variable variable = new Variable(v, mivar);
addVariable(variable);
return variable;
}
/**
* Tell gdb to remove the underlying var-object also.
*/
void removeMIVar(MIVar miVar) throws CDIException {
MISession mi = getCSession().getMISession();
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarDelete var = factory.createMIVarDelete(miVar.getVarName());
try {
@ -220,146 +137,286 @@ public class VariableManager extends SessionObject implements ICDIExpressionMana
* because they are still needed for the destroy events. The destroy event will
* call removeOutOfScope.
*/
void removeElement(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]);
oosList.add(elements[i]); // Put on the Out Of Scope list
removeMIVar(elements[i].miVar);
public void removeVariable(String varName) throws CDIException {
Variable[] vars = getVariables();
for (int i = 0; i < vars.length; i++) {
if (vars[i].getMIVar().getVarName().equals(varName)) {
variableList.remove(vars[i]);
removeMIVar(vars[i].getMIVar());
}
}
}
/**
* Finds the variable Uniq name and call removeElement().
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#createArgument(ICDIArgumentObject)
*/
void removeElement(MIVarChange changed) throws CDIException {
String varName = changed.getVarName();
removeElement(varName);
public ICDIArgument createArgument(ICDIArgumentObject a) throws CDIException {
if (a instanceof ArgumentObject) {
ArgumentObject argObj = (ArgumentObject)a;
Variable variable = findVariable(argObj);
Argument argument = null;
if (variable != null && variable instanceof Argument) {
argument = (Argument)variable;
}
if (argument == null) {
StackFrame stack = argObj.getStackFrame();
String name = argObj.getName();
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
Thread currentThread = (Thread)currentTarget.getCurrentThread();
StackFrame currentFrame = (StackFrame)currentThread.getCurrentStackFrame();
((Thread)stack.getThread()).setCurrentStackFrame(stack, false);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarCreate var = factory.createMIVarCreate(name);
mi.postCommand(var);
MIVarCreateInfo info = var.getMIVarCreateInfo();
if (info == null) {
throw new CDIException("No answer");
}
argument = new Argument(argObj, info.getMIVar());
addVariable(argument);
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
currentThread.setCurrentStackFrame(currentFrame, false);
}
}
return argument;
}
throw new CDIException("Wrong variable type");
}
/**
* Remove the Element.
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getArgumentObject(ICDIStackFrame, String)
*/
void removeElement(Variable variable) throws CDIException {
String varName = ((Variable)variable).getMIVar().getVarName();
removeElement(varName);
}
/**
* Remove the elements.
*/
void removeElements(Variable[] variables) throws CDIException {
for (int i = 0; i < variables.length; i++) {
removeElement(variables[i]);
}
}
public ICDIVariable createVariable(StackFrame stack, String name) throws CDIException {
Element element = createElement(stack, name);
Variable var;
if (element.variable != null) {
var = element.variable;
} else {
var = new Variable(stack, name, element.miVar);
element.variable = var;
addElement(element);
// Fire an created Event.
MISession mi = getCSession().getMISession();
mi.fireEvent(new MIVarCreatedEvent(element.miVar.getVarName()));
}
return var;
}
public Variable createVariable(StackFrame stack, String name, MIVar miVar )
public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name)
throws CDIException {
Element element = new Element();
element.miVar = miVar;
element.name = name;
element.stackframe = stack;
Variable var = new Variable(stack, name, miVar);
element.variable = var;
addElement(element);
// Fire an created Event.
MISession mi = getCSession().getMISession();
mi.fireEvent(new MIVarCreatedEvent(miVar.getVarName()));
return var;
}
public ICDIArgument createArgument(StackFrame stack, String name) throws CDIException {
Element element = createElement(stack, name);
Argument carg;
if (element.variable != null && element.variable instanceof Argument) {
carg = (Argument)element.variable;
} else {
carg = new Argument(stack, name,element.miVar);
element.variable = carg;
addElement(element);
// Fire an created Event.
MISession mi = getCSession().getMISession();
mi.fireEvent(new MIVarCreatedEvent(element.miVar.getVarName()));
}
return carg;
}
ICDIExpression createExpression(StackFrame stack, String name) throws CDIException {
Element element = createElement(stack, name);
Expression cexp;
if (element.variable != null && element.variable instanceof Expression) {
cexp = (Expression)element.variable;
} else {
cexp = new Expression(stack, name, element.miVar);
element.variable = cexp;
addElement(element);
// Fire an created Event.
MISession mi = getCSession().getMISession();
mi.fireEvent(new MIVarCreatedEvent(element.miVar.getVarName()));
}
return cexp;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#createExpression(String)
*/
public ICDIExpression createExpression(String name) throws CDIException {
CTarget target = getCSession().getCTarget();
StackFrame frame = ((CThread)target.getCurrentThread()).getCurrentStackFrame();
return createExpression(frame, name);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#getExpressions()
*/
public ICDIExpression[] getExpressions() throws CDIException {
Element[] elements = getElements();
List aList = new ArrayList(elements.length);
for (int i = 0; i < elements.length; i++) {
if (elements[i].variable instanceof ICDIExpression) {
aList.add(elements[i].variable);
ICDIArgumentObject[] argsObjects = getArgumentObjects(stack);
for (int i = 0; i < argsObjects.length; i++) {
if (argsObjects[i].getName().equals(name)) {
return argsObjects[i];
}
}
return (ICDIExpression[])aList.toArray(new ICDIExpression[0]);
return null;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression)
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getArgumentObjects(ICDIStackFrame)
*/
public void removeExpression(ICDIExpression expression)
throws CDIException {
if (expression instanceof Variable) {
removeElement((Variable)expression);
public ICDIArgumentObject[] getArgumentObjects(ICDIStackFrame frame) throws CDIException {
if (!(frame instanceof StackFrame)) {
return new ICDIArgumentObject[0];
}
List argObjects = new ArrayList();
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
Thread currentThread = (Thread)currentTarget.getCurrentThread();
StackFrame currentFrame = (StackFrame)currentThread.getCurrentStackFrame();
((Thread)(frame.getThread())).setCurrentStackFrame((StackFrame)frame, false);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
int depth = frame.getThread().getStackFrameCount();
int level = frame.getLevel();
MIStackListArguments listArgs =
factory.createMIStackListArguments(false, level, level);
MIArg[] args = null;
mi.postCommand(listArgs);
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) {
for (int i = 0; i < args.length; i++) {
ArgumentObject arg = new ArgumentObject(args[i].getName(),
(StackFrame)frame, args.length - i, depth);
argObjects.add(arg);
}
}
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
currentThread.setCurrentStackFrame(currentFrame);
}
return (ICDIArgumentObject[])argObjects.toArray(new ICDIArgumentObject[0]);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getVariableObject(ICDIStackFrame, String)
*/
public ICDIVariableObject getVariableObject(ICDIStackFrame stack, String name) throws CDIException {
ICDIVariableObject[] varObjects = getVariableObjects(stack);
for (int i = 0; i < varObjects.length; i++) {
if (varObjects[i].getName().equals(name)) {
return varObjects[i];
}
}
return null;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getVariableObject(String, String, String)
*/
public ICDIVariableObject getVariableObject(String filename, String function, String name) throws CDIException {
if (filename == null) {
filename = new String();
}
if (function == null) {
function = new String();
}
if (name == null) {
name = new String();
}
StringBuffer buffer = new StringBuffer();
if (filename.length() > 0) {
buffer.append('\'').append(filename).append('\'').append("::");
}
if (function.length() > 0) {
buffer.append(function).append("::");
}
buffer.append(name);
return new VariableObject(buffer.toString(), null, 0, 0);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getVariableObjects(ICDIStackFrame)
*/
public ICDIVariableObject[] getVariableObjects(ICDIStackFrame frame) throws CDIException {
if (!(frame instanceof StackFrame)) {
return new ICDIVariableObject[0];
}
List varObjects = new ArrayList();
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
Thread currentThread = (Thread)currentTarget.getCurrentThread();
StackFrame currentFrame = (StackFrame)currentThread.getCurrentStackFrame();
((Thread)(frame.getThread())).setCurrentStackFrame((StackFrame)frame, false);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
int depth = frame.getThread().getStackFrameCount();
MIArg[] args = null;
MIStackListLocals locals = factory.createMIStackListLocals(false);
mi.postCommand(locals);
MIStackListLocalsInfo info = locals.getMIStackListLocalsInfo();
if (info == null) {
throw new CDIException("No answer");
}
args = info.getLocals();
if (args != null) {
for (int i = 0; i < args.length; i++) {
VariableObject varObj = new VariableObject(args[i].getName(),
(StackFrame)frame, args.length - i, depth);
varObjects.add(varObj);
}
}
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
currentThread.setCurrentStackFrame((StackFrame)currentFrame, false);
}
return (ICDIVariableObject[])varObjects.toArray(new ICDIVariableObject[0]);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#createVariable(ICDIVariableObject)
*/
public ICDIVariable createVariable(ICDIVariableObject v) throws CDIException {
if (v instanceof VariableObject) {
VariableObject varObj = (VariableObject)v;
Variable variable = findVariable(varObj);
if (variable == null) {
StackFrame stack = varObj.getStackFrame();
String name = varObj.getName();
Session session = (Session)getSession();
ICDITarget currentTarget = session.getCurrentTarget();
Thread currentThread = (Thread)currentTarget.getCurrentThread();
StackFrame currentFrame = (StackFrame)currentThread.getCurrentStackFrame();
((Thread)stack.getThread()).setCurrentStackFrame(stack, false);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarCreate var = factory.createMIVarCreate(name);
mi.postCommand(var);
MIVarCreateInfo info = var.getMIVarCreateInfo();
if (info == null) {
throw new CDIException("No answer");
}
variable = new Variable(varObj, info.getMIVar());
addVariable(variable);
} catch (MIException e) {
throw new MI2CDIException(e);
} finally {
currentThread.setCurrentStackFrame(currentFrame, false);
}
}
return variable;
}
throw new CDIException("Wrong variable type");
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#destroyVariable(ICDIVariable)
*/
public void destroyVariable(ICDIVariable var) throws CDIException {
if (var instanceof Variable) {
// Fire a destroyEvent ?
Variable variable = (Variable)var;
MIVarChangedEvent change = new MIVarChangedEvent(0, variable.getMIVar().getVarName(), false);
Session session = (Session)getSession();
MISession mi = session.getMISession();
mi.fireEvent(change);
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpressions(ICDIExpression[])
* @see org.eclipse.cdt.debug.mi.core.cdi.IVarUpdateListener#changeList(MIVarChange[])
*/
public void removeExpressions(ICDIExpression[] expressions)
throws CDIException {
for (int i = 0; i < expressions.length; i++) {
removeExpression(expressions[i]);
public void changeList(MIVarChange[] changes) {
List eventList = new ArrayList(changes.length);
for (int i = 0 ; i < changes.length; i++) {
String varName = changes[i].getVarName();
Variable variable = getVariable(varName);
if (variable != null) {
eventList.add(new MIVarChangedEvent(0, varName, changes[i].isInScope()));
}
}
Session session = (Session)getSession();
MISession mi = session.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#isAutoUpdate()
*/
public boolean isAutoUpdate() {
return autoupdate;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#setAutoUpdate(boolean)
*/
public void setAutoUpdate(boolean update) {
autoupdate = update;
}
/**
* Update the elements in the cache, from the response of the "-var-update *"
* mi/command.
*
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#createArgument(ICDIArgumentObject)
*/
public void update() throws CDIException {
Session session = (Session)getSession();
UpdateManager mgr = session.getUpdateManager();
mgr.update();
}
}

View file

@ -0,0 +1,47 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.cdi;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableObject;
import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame;
/**
*/
public class VariableObject implements ICDIVariableObject {
String name;
int position;
StackFrame frame;
int stackdepth;
public VariableObject(String n, StackFrame stack, int pos, int depth) {
name = n;
frame = stack;
position = pos;
stackdepth = depth;
}
public StackFrame getStackFrame() {
return frame;
}
public int getPosition() {
return position;
}
public int getStackDepth() {
return stackdepth;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableObject#getName()
*/
public String getName() {
return name;
}
}

View file

@ -16,7 +16,7 @@ public class WatchpointScope extends SessionObject implements ICDIWatchpointScop
MIWatchpointScopeEvent watchEvent;
public WatchpointScope(CSession session, MIWatchpointScopeEvent e) {
public WatchpointScope(Session session, MIWatchpointScopeEvent e) {
super(session);
watchEvent = e;
}
@ -27,7 +27,7 @@ public class WatchpointScope extends SessionObject implements ICDIWatchpointScop
public ICDIWatchpoint getWatchpoint() {
int number = watchEvent.getNumber();
// Ask the breakpointManager for the breakpoint
BreakpointManager mgr = (BreakpointManager)getCSession().getBreakpointManager();
BreakpointManager mgr = (BreakpointManager)getSession().getBreakpointManager();
// We need to return the same object as the reason.
Watchpoint point = mgr.getWatchpoint(number);
// FIXME: if point ==null ??? Create a new breakpoint ?

View file

@ -16,7 +16,7 @@ public class WatchpointTrigger extends SessionObject implements ICDIWatchpointTr
MIWatchpointTriggerEvent watchEvent;
public WatchpointTrigger(CSession session, MIWatchpointTriggerEvent e) {
public WatchpointTrigger(Session session, MIWatchpointTriggerEvent e) {
super(session);
watchEvent = e;
}
@ -41,7 +41,7 @@ public class WatchpointTrigger extends SessionObject implements ICDIWatchpointTr
public ICDIWatchpoint getWatchpoint() {
int number = watchEvent.getNumber();
// Ask the breakpointManager for the breakpoint
BreakpointManager mgr = (BreakpointManager)getCSession().getBreakpointManager();
BreakpointManager mgr = (BreakpointManager)getSession().getBreakpointManager();
// We need to return the same object as the reason.
Watchpoint point = mgr.getWatchpoint(number);
// FIXME: if point ==null ??? Create a new breakpoint ?

View file

@ -23,7 +23,7 @@ public class Breakpoint extends CObject implements ICDILocationBreakpoint {
BreakpointManager mgr;
public Breakpoint(BreakpointManager m, MIBreakpoint miBreak) {
super(m.getCSession().getCTarget());
super(m.getSession().getCurrentTarget());
miBreakpoint = miBreak;
mgr = m;
}

View file

@ -11,9 +11,9 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
*/
public class CObject implements ICDIObject {
CTarget target;
ICDITarget target;
public CObject(CTarget t) {
public CObject(ICDITarget t) {
target = t;
}
@ -23,9 +23,5 @@ public class CObject implements ICDIObject {
public ICDITarget getTarget() {
return target;
}
public CTarget getCTarget() {
return target;
}
}

View file

@ -6,13 +6,14 @@
package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
import org.eclipse.cdt.debug.mi.core.cdi.VariableObject;
import org.eclipse.cdt.debug.mi.core.output.MIVar;
/**
*/
public class Expression extends Variable implements ICDIExpression {
public Expression(StackFrame stackframe, String name, MIVar var) {
super(stackframe, name, var);
public Expression(VariableObject obj, MIVar var) {
super(obj, var);
}
}

View file

@ -6,6 +6,7 @@
package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.output.MIAsm;
/**
@ -14,7 +15,7 @@ public class Instruction extends CObject implements ICDIInstruction {
MIAsm asm;
public Instruction(CTarget target, MIAsm a) {
public Instruction(ICDITarget target, MIAsm a) {
super(target);
asm = a;
}

View file

@ -5,11 +5,13 @@ import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MIFormat;
import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.cdi.MI2CDIException;
import org.eclipse.cdt.debug.mi.core.cdi.MemoryManager;
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.MIDataWriteMemory;
import org.eclipse.cdt.debug.mi.core.output.MIDataReadMemoryInfo;
@ -25,7 +27,7 @@ public class MemoryBlock extends CObject implements ICDIMemoryBlock {
boolean frozen;
boolean dirty;
public MemoryBlock(CTarget target, String exp, MIDataReadMemoryInfo info) {
public MemoryBlock(ICDITarget target, String exp, MIDataReadMemoryInfo info) {
super(target);
expression = exp;
mem = info;
@ -115,7 +117,7 @@ public class MemoryBlock extends CObject implements ICDIMemoryBlock {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock#refresh()
*/
public void refresh() throws CDIException {
MemoryManager mgr = (MemoryManager)getCTarget().getCSession().getMemoryManager();
MemoryManager mgr = (MemoryManager)getTarget().getSession().getMemoryManager();
setDirty(true);
Long[] addresses = mgr.update(this, null);
// Check if this affects other blocks.
@ -165,7 +167,8 @@ public class MemoryBlock extends CObject implements ICDIMemoryBlock {
if (offset >= getLength() || offset + bytes.length > getLength()) {
throw new CDIException("Bad Offset");
}
MISession mi = getCTarget().getCSession().getMISession();
Session session = (Session)getTarget().getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
for (int i = 0; i < bytes.length; i++) {
long l = new Byte(bytes[i]).longValue() & 0xff;

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction;
import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.output.MIAsm;
import org.eclipse.cdt.debug.mi.core.output.MISrcAsm;
@ -16,7 +17,7 @@ public class MixedInstruction extends CObject implements ICDIMixedInstruction {
MISrcAsm srcAsm;
public MixedInstruction (CTarget target, MISrcAsm a) {
public MixedInstruction (ICDITarget target, MISrcAsm a) {
super(target);
srcAsm = a;
}
@ -35,7 +36,7 @@ public class MixedInstruction extends CObject implements ICDIMixedInstruction {
MIAsm[] asms = srcAsm.getMIAsms();
ICDIInstruction[] instructions = new ICDIInstruction[asms.length];
for (int i = 0; i < asms.length; i++) {
instructions[i] = new Instruction(getCTarget(), asms[i]);
instructions[i] = new Instruction(getTarget(), asms[i]);
}
return instructions;
}

View file

@ -12,6 +12,8 @@ import java.util.StringTokenizer;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject;
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.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.mi.core.MIException;
@ -20,6 +22,7 @@ import org.eclipse.cdt.debug.mi.core.MISession;
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.RegisterObject;
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.MIDataListRegisterValues;
import org.eclipse.cdt.debug.mi.core.command.MIDataWriteRegisterValues;
@ -43,12 +46,12 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
* gdb/mi -data-list-register-values returns the value like this
* value="{f = {0x0, 0x0, 0x0, 0x0}}"
* we'll parse() it and change it to:
* Argument[0] = { "xmm0", "{f = {0x0, 0x0, 0x0, 0x0}}"
* Argument[1] = { "xmm0.f", "{0x0, 0x0, 0x0, 0x0}"}
* Argument[0] = { "xmm0", "{f = {0x0, 0x1, 0x2, 0x3}}"}
* Argument[1] = { "xmm0.f", "{0x0, 0x1, 0x2, 0x3}"}
* Argument[2] = { "xmm0.f.0", "0x0"}
* Argument[3] = { "xmm0.f.1", "0x0"}
* Argument[4] = { "xmm0.f.2", "0x0"}
* Argument[5] = { "xmm0.f.3", "0x0"}
* Argument[3] = { "xmm0.f.1", "0x1"}
* Argument[4] = { "xmm0.f.2", "0x2"}
* Argument[5] = { "xmm0.f.3", "0x3"}
* see @parse()
*/
class Argument {
@ -66,7 +69,7 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
}
}
public Register(CTarget target, ICDIRegisterObject r) {
public Register(ICDITarget target, ICDIRegisterObject r) {
super(target);
parent = null;
lastname = r.getName();
@ -74,7 +77,7 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
}
public Register(Register p, String n) {
super(p.getCTarget());
super(p.getTarget());
parent = p;
lastname = n;
}
@ -83,7 +86,7 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
* return the MI regno.
*/
public int getID() {
return regObject.getId();
return regObject.getPosition();
}
/**
@ -151,9 +154,10 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
*/
public String getValueString() throws CDIException {
if (parent == null) {
MISession mi = getCTarget().getCSession().getMISession();
Session session = (Session)getTarget().getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
int[] regno = new int[]{regObject.getId()};
int[] regno = new int[]{regObject.getPosition()};
MIDataListRegisterValues registers =
factory.createMIDataListRegisterValues(format, regno);
try {
@ -204,9 +208,10 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(String)
*/
public void setValue(String expression) throws CDIException {
MISession mi = getCTarget().getCSession().getMISession();
Session session = (Session)getTarget().getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
int[] regnos = new int[]{regObject.getId()};
int[] regnos = new int[]{regObject.getPosition()};
String[] values = new String[]{expression};
MIDataWriteRegisterValues registers =
factory.createMIDataWriteRegisterValues(format, regnos, values);
@ -221,7 +226,7 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
}
// If the assign was succesfull fire a MIRegisterChangedEvent()
MIRegisterChangedEvent change = new MIRegisterChangedEvent(registers.getToken(),
regObject.getName(), regObject.getId());
regObject.getName(), regObject.getPosition());
mi.fireEvent(change);
}
@ -317,4 +322,12 @@ public class Register extends CObject implements ICDIRegister, ICDIValue {
}
return (Argument[])aList.toArray(new Argument[0]);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getStackFrame()
*/
public ICDIStackFrame getStackFrame() throws CDIException {
return null;
}
}

View file

@ -20,7 +20,7 @@ public class SharedLibrary extends CObject implements ICDISharedLibrary {
MIShared miShared;
public SharedLibrary(SharedLibraryManager m, MIShared slib) {
super(m.getCSession().getCTarget());
super(m.getSession().getCurrentTarget());
mgr = m;
miShared = slib;
}

View file

@ -6,6 +6,7 @@
package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.model.ICDISignal;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
/**
@ -13,7 +14,7 @@ import org.eclipse.cdt.debug.mi.core.event.MISignalEvent;
public class Signal extends CObject implements ICDISignal {
MISignalEvent event;
public Signal(CTarget target, MISignalEvent e) {
public Signal(ICDITarget target, MISignalEvent e) {
super(target);
event = e;
}

View file

@ -5,36 +5,28 @@
*/
package org.eclipse.cdt.debug.mi.core.cdi.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIArgumentObject;
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.ICDIVariableObject;
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument;
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.ICDIVariable;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.cdi.CSession;
import org.eclipse.cdt.debug.mi.core.cdi.Session;
import org.eclipse.cdt.debug.mi.core.cdi.Location;
import org.eclipse.cdt.debug.mi.core.cdi.VariableManager;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIStackListArguments;
import org.eclipse.cdt.debug.mi.core.command.MIStackListLocals;
import org.eclipse.cdt.debug.mi.core.output.MIArg;
import org.eclipse.cdt.debug.mi.core.output.MIFrame;
import org.eclipse.cdt.debug.mi.core.output.MIStackListArgumentsInfo;
import org.eclipse.cdt.debug.mi.core.output.MIStackListLocalsInfo;
/**
*/
public class StackFrame extends CObject implements ICDIStackFrame {
MIFrame frame;
CThread cthread;
Thread cthread;
public StackFrame(CThread thread, MIFrame f) {
super(thread.getCTarget());
public StackFrame(Thread thread, MIFrame f) {
super(thread.getTarget());
cthread = thread;
frame = f;
}
@ -43,7 +35,10 @@ public class StackFrame extends CObject implements ICDIStackFrame {
return frame;
}
public CThread getCThread() {
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getThread()
*/
public ICDIThread getThread() {
return cthread;
}
@ -51,82 +46,28 @@ public class StackFrame extends CObject implements ICDIStackFrame {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getArguments()
*/
public ICDIArgument[] getArguments() throws CDIException {
List cdiList = new ArrayList();
if (frame != null) {
CSession session = getCTarget().getCSession();
VariableManager mgr = (VariableManager)session.getVariableManager();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
int level = frame.getLevel();
MIStackListArguments listArgs =
factory.createMIStackListArguments(false, level, level);
try {
cthread.setCurrentStackFrame(this);
MIArg[] args = null;
mi.postCommand(listArgs);
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) {
for (int i = 0; i < args.length; i++) {
try {
cdiList.add(mgr.createArgument(this, args[i].getName()));
} catch (CDIException e) {
}
}
}
} catch (MIException e) {
//throw new CDIException(e.getMessage());
//System.err.println(e);
} catch (CDIException e) {
//throw e;
//System.err.println(e);
}
Session session = (Session)getTarget().getSession();
VariableManager mgr = (VariableManager)session.getVariableManager();
ICDIArgumentObject[] argObjs = mgr.getArgumentObjects(this);
ICDIArgument[] args = new ICDIArgument[argObjs.length];
for (int i = 0; i < args.length; i++) {
args[i] = mgr.createArgument(argObjs[i]);
}
return (ICDIArgument[])cdiList.toArray(new ICDIArgument[0]);
return args;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame#getLocalVariables()
*/
public ICDIVariable[] getLocalVariables() throws CDIException {
List cdiList = new ArrayList();
CSession session = getCTarget().getCSession();
Session session = (Session)getTarget().getSession();
VariableManager mgr = (VariableManager)session.getVariableManager();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackListLocals locals = factory.createMIStackListLocals(false);
try {
cthread.setCurrentStackFrame(this);
MIArg[] args = null;
mi.postCommand(locals);
MIStackListLocalsInfo info = locals.getMIStackListLocalsInfo();
if (info == null) {
throw new CDIException("No answer");
}
args = info.getLocals();
if (args != null) {
for (int i = 0; i < args.length; i++) {
try {
cdiList.add(mgr.createVariable(this, args[i].getName()));
} catch (CDIException e) {
}
}
}
} catch (MIException e) {
//throw new CDIException(e.getMessage());
//System.err.println(e);
} catch (CDIException e) {
//throw e;
//System.err.println(e);
ICDIVariableObject[] varObjs = mgr.getVariableObjects(this);
ICDIVariable[] vars = new ICDIVariable[varObjs.length];
for (int i = 0; i < vars.length; i++) {
vars[i] = mgr.createVariable(varObjs[i]);
}
return (ICDIVariable[])cdiList.toArray(new ICDIVariable[0]);
return vars;
}
/**
@ -156,7 +97,7 @@ public class StackFrame extends CObject implements ICDIStackFrame {
if (stackframe instanceof StackFrame) {
StackFrame stack = (StackFrame)stackframe;
return cthread != null &&
cthread.equals(stack.getCThread()) &&
cthread.equals(stack.getThread()) &&
frame != null &&
frame.getLevel() == stack.getMIFrame().getLevel() &&
frame.getFile().equals(stack.getMIFrame().getFile()) &&

View file

@ -10,18 +10,18 @@ import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterManager;
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariable;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
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.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.cdi.CSession;
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.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIDataEvaluateExpression;
import org.eclipse.cdt.debug.mi.core.command.MIExecContinue;
@ -45,20 +45,20 @@ import org.eclipse.cdt.debug.mi.core.output.MIThreadSelectInfo;
/**
*/
public class CTarget implements ICDITarget {
public class Target implements ICDITarget {
CSession session;
CThread[] noThreads = new CThread[0];
CThread[] currentThreads;
Session session;
Thread[] noThreads = new Thread[0];
Thread[] currentThreads;
int currentThreadId;
int lastExecutionToken;
public CTarget(CSession s) {
public Target(Session s) {
session = s;
currentThreads = noThreads;
}
public CSession getCSession() {
public Session getCSession() {
return session;
}
@ -84,19 +84,27 @@ public class CTarget implements ICDITarget {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#setCurrentThread(ICDIThread)
*/
public void setCurrentThread(ICDIThread cthread) throws CDIException {
setCurrentThread(cthread, true);
if (cthread instanceof Thread) {
setCurrentThread(cthread, true);
} else {
throw new CDIException("unknown thread");
}
}
public void setCurrentThread(ICDIThread cthread, boolean doUpdate) throws CDIException {
if (cthread instanceof CThread) {
setCurrentThread((CThread)cthread, doUpdate);
if (cthread instanceof Thread) {
setCurrentThread((Thread)cthread, doUpdate);
} else {
throw new CDIException("unknown thread");
}
}
/**
*/
public void setCurrentThread(CThread cthread, boolean doUpdate) throws CDIException {
public void setCurrentThread(Thread cthread, boolean doUpdate) throws CDIException {
// set us as the current target.
session.setCurrentTarget(this);
int id = cthread.getId();
// No need to set thread id 0, it is a dummy thread.
if (id == 0) {
@ -122,7 +130,7 @@ public class CTarget implements ICDITarget {
// some variables like Register. Send an update
// To generate changeEvents.
if (doUpdate) {
RegisterManager regMgr = session.getRegisterManager();
RegisterManager regMgr = (RegisterManager)session.getRegisterManager();
regMgr.update();
}
}
@ -140,75 +148,74 @@ public class CTarget implements ICDITarget {
* Called when stopping because of breakpoints etc ..
*/
public void updateState(int newThreadId) {
CThread[] oldThreads = currentThreads;
Thread[] oldThreads = currentThreads;
// If we use "info threads" in getCThreads() this
// will be overwritten. However if we use -stack-list-threads
// it does not provide to the current thread
currentThreadId = newThreadId;
// get the new Threads.
CThread[] newThreads = getCThreads();
currentThreads = newThreads;
// get the new Threads.
currentThreads = getCThreads();
// Fire CreatedEvent for new threads.
if (newThreads != null && newThreads.length > 0) {
List cList = new ArrayList(newThreads.length);
for (int i = 0; i < newThreads.length; i++) {
boolean found = false;
for (int j = 0; oldThreads != null && j < oldThreads.length; j++) {
if (newThreads[i].getId() == ((CThread)oldThreads[j]).getId()) {
found = true;
break;
}
}
if (!found) {
cList.add(new Integer(newThreads[i].getId()));
// Replace the new threads with the old thread object
// User may have old on to the old Thread object.
List cList = new ArrayList(currentThreads.length);
for (int i = 0; i < currentThreads.length; i++) {
boolean found = false;
for (int j = 0; j < oldThreads.length; j++) {
if (currentThreads[i].getId() == oldThreads[j].getId()) {
oldThreads[j].clearState();
currentThreads[i] = oldThreads[j];
found = true;
break;
}
}
if (!cList.isEmpty()) {
MIThreadCreatedEvent[] events = new MIThreadCreatedEvent[cList.size()];
for (int j = 0; j < events.length; j++) {
int id = ((Integer)cList.get(j)).intValue();
events[j] = new MIThreadCreatedEvent(id);
}
MISession miSession = session.getMISession();
miSession.fireEvents(events);
if (!found) {
cList.add(new Integer(currentThreads[i].getId()));
}
}
if (!cList.isEmpty()) {
MIThreadCreatedEvent[] events = new MIThreadCreatedEvent[cList.size()];
for (int j = 0; j < events.length; j++) {
int id = ((Integer)cList.get(j)).intValue();
events[j] = new MIThreadCreatedEvent(id);
}
MISession miSession = session.getMISession();
miSession.fireEvents(events);
}
// Fire destroyedEvent for old threads.
if (oldThreads != null && oldThreads.length > 0) {
List dList = new ArrayList(oldThreads.length);
for (int i = 0; i < oldThreads.length; i++) {
boolean found = false;
for (int j = 0; newThreads != null && j < newThreads.length; j++) {
if (newThreads[j].getId() == ((CThread)oldThreads[i]).getId()) {
found = true;
break;
}
}
if (!found) {
dList.add(new Integer(oldThreads[i].getId()));
List dList = new ArrayList(oldThreads.length);
for (int i = 0; i < oldThreads.length; i++) {
boolean found = false;
for (int j = 0; j < currentThreads.length; j++) {
if (currentThreads[j].getId() == oldThreads[i].getId()) {
found = true;
break;
}
}
if (!dList.isEmpty()) {
MIThreadExitEvent[] events = new MIThreadExitEvent[dList.size()];
for (int j = 0; j < events.length; j++) {
int id = ((Integer)dList.get(j)).intValue();
events[j] = new MIThreadExitEvent(id);
}
MISession miSession = session.getMISession();
miSession.fireEvents(events);
if (!found) {
dList.add(new Integer(oldThreads[i].getId()));
}
}
if (!dList.isEmpty()) {
MIThreadExitEvent[] events = new MIThreadExitEvent[dList.size()];
for (int j = 0; j < events.length; j++) {
int id = ((Integer)dList.get(j)).intValue();
events[j] = new MIThreadExitEvent(id);
}
MISession miSession = session.getMISession();
miSession.fireEvents(events);
}
}
/**
* Do the real work of call -thread-list-ids.
*/
public CThread[] getCThreads() { //throws CDIException {
CThread[] cthreads = noThreads;
public Thread[] getCThreads() { //throws CDIException {
Thread[] cthreads = noThreads;
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIInfoThreads tids = factory.createMIInfoThreads();
@ -227,14 +234,14 @@ public class CTarget implements ICDITarget {
ids = info.getThreadIds();
}
if (ids != null && ids.length > 0) {
cthreads = new CThread[ids.length];
cthreads = new Thread[ids.length];
// Ok that means it is a multiThreaded.
for (int i = 0; i < ids.length; i++) {
cthreads[i] = new CThread(this, ids[i]);
cthreads[i] = new Thread(this, ids[i]);
}
} else {
// Provide a dummy.
cthreads = new CThread[]{new CThread(this, 0)};
cthreads = new Thread[]{new Thread(this, 0)};
}
currentThreadId = info.getCurrentThread();
} catch (MIException e) {
@ -250,7 +257,7 @@ public class CTarget implements ICDITarget {
public ICDIThread getCurrentThread() throws CDIException {
ICDIThread[] threads = getThreads();
for (int i = 0; i < threads.length; i++) {
CThread cthread = (CThread)threads[i];
Thread cthread = (Thread)threads[i];
if (cthread.getId() == currentThreadId) {
return cthread;
}
@ -269,10 +276,10 @@ public class CTarget implements ICDITarget {
}
public ICDIThread getThread(int tid) {
CThread th = null;
Thread th = null;
if (currentThreads != null) {
for (int i = 0; i < currentThreads.length; i++) {
CThread cthread = (CThread)currentThreads[i];
Thread cthread = (Thread)currentThreads[i];
if (cthread.getId() == tid) {
th = cthread;
break;
@ -560,19 +567,12 @@ public class CTarget implements ICDITarget {
public boolean isRunning() {
return session.getMISession().getMIInferior().isRunning();
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getGlobalVariables()
*/
public ICDIGlobalVariable[] getGlobalVariables() throws CDIException {
return new ICDIGlobalVariable[0];
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDITarget#getRegisterObjects()
*/
public ICDIRegisterObject[] getRegisterObjects() throws CDIException {
RegisterManager mgr = session.getRegisterManager();
ICDIRegisterManager mgr = session.getRegisterManager();
return mgr.getRegisterObjects();
}
@ -581,7 +581,7 @@ public class CTarget implements ICDITarget {
*/
public ICDIRegister[] getRegisters(ICDIRegisterObject[] regs) throws CDIException {
ICDIRegister[] registers = null;
RegisterManager mgr = session.getRegisterManager();
ICDIRegisterManager mgr = session.getRegisterManager();
registers = new ICDIRegister[regs.length];
for (int i = 0; i < registers.length; i++) {
registers[i] = mgr.createRegister(regs[i]);

View file

@ -8,12 +8,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.ICDILocation;
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.CSession;
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.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIStackInfoDepth;
import org.eclipse.cdt.debug.mi.core.command.MIStackListFrames;
@ -25,13 +26,14 @@ import org.eclipse.cdt.debug.mi.core.output.MIStackListFramesInfo;
/**
*/
public class CThread extends CObject implements ICDIThread {
public class Thread extends CObject implements ICDIThread {
int id;
static StackFrame[] noStack = new StackFrame[0];
int id;
StackFrame currentFrame;
int stackdepth = 0;
public CThread(CTarget target, int threadId) {
public Thread(ICDITarget target, int threadId) {
super(target);
id = threadId;
}
@ -40,11 +42,16 @@ public class CThread extends CObject implements ICDIThread {
return id;
}
public void clearState() {
stackdepth = 0;
currentFrame = null;
}
public String toString() {
return Integer.toString(id);
}
public StackFrame getCurrentStackFrame() throws CDIException {
public ICDIStackFrame getCurrentStackFrame() throws CDIException {
if (currentFrame == null) {
ICDIStackFrame[] frames = getStackFrames(0, 0);
if (frames.length > 0) {
@ -59,94 +66,113 @@ public class CThread extends CObject implements ICDIThread {
*/
public ICDIStackFrame[] getStackFrames() throws CDIException {
StackFrame[] stack = noStack;
CSession session = getCTarget().getCSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames();
StackFrame[] stacks = noStack;
Session session = (Session)getTarget().getSession();
Target currentTarget = (Target)session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread();
currentTarget.setCurrentThread(this, false);
try {
ICDIThread oldThread = getCTarget().getCurrentThread();
getCTarget().setCurrentThread(this, false);
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames();
mi.postCommand(frames);
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
if (info == null) {
throw new CDIException("No answer");
}
MIFrame[] miFrames = info.getMIFrames();
stack = new StackFrame[miFrames.length];
for (int i = 0; i < stack.length; i++) {
stack[i] = new StackFrame(this, miFrames[i]);
stacks = new StackFrame[miFrames.length];
for (int i = 0; i < stacks.length; i++) {
stacks[i] = new StackFrame(this, miFrames[i]);
}
getCTarget().setCurrentThread(oldThread, false);
return stack;
} catch (MIException e) {
//throw new CDIException(e.getMessage());
//System.out.println(e);
} catch (CDIException e) {
//throw e;
//System.out.println(e);
} finally {
currentTarget.setCurrentThread(currentThread, false);
}
return stack;
if (currentFrame == null) {
for (int i = 0; i < stacks.length; i++) {
if (stacks[i].getLevel() == 0) {
currentFrame = stacks[i];
}
}
}
return stacks;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames()
*/
public int getStackFrameCount() throws CDIException {
CSession session = getCTarget().getCSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackInfoDepth depth = factory.createMIStackInfoDepth();
try {
ICDIThread oldThread = getCTarget().getCurrentThread();
getCTarget().setCurrentThread(this, false);
mi.postCommand(depth);
MIStackInfoDepthInfo info = depth.getMIStackInfoDepthInfo();
if (info == null) {
throw new CDIException("No answer");
if (stackdepth == 0) {
Session session = (Session)(getTarget().getSession());
Target currentTarget = (Target)session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread();
currentTarget.setCurrentThread(this, false);
try {
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackInfoDepth depth = factory.createMIStackInfoDepth();
mi.postCommand(depth);
MIStackInfoDepthInfo info = depth.getMIStackInfoDepthInfo();
if (info == null) {
throw new CDIException("No answer");
}
stackdepth = info.getDepth();
} catch (MIException e) {
throw new MI2CDIException(e);
//System.out.println(e);
} finally {
currentTarget.setCurrentThread(currentThread, false);
}
getCTarget().setCurrentThread(oldThread, false);
return info.getDepth();
} catch (MIException e) {
throw new MI2CDIException(e);
//System.out.println(e);
}
return stackdepth;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#getStackFrames()
*/
public ICDIStackFrame[] getStackFrames(int low, int high) throws CDIException {
StackFrame[] stack = noStack;
CSession session = getCTarget().getCSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames(low, high);
StackFrame[] stacks = noStack;
Session session = (Session)getTarget().getSession();
Target currentTarget = (Target)session.getCurrentTarget();
ICDIThread currentThread = currentTarget.getCurrentThread();
currentTarget.setCurrentThread(this, false);
try {
ICDIThread oldThread = getCTarget().getCurrentThread();
getCTarget().setCurrentThread(this, false);
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackListFrames frames = factory.createMIStackListFrames(low, high);
mi.postCommand(frames);
MIStackListFramesInfo info = frames.getMIStackListFramesInfo();
if (info == null) {
throw new CDIException("No answer");
}
MIFrame[] miFrames = info.getMIFrames();
stack = new StackFrame[miFrames.length];
for (int i = 0; i < stack.length; i++) {
stack[i] = new StackFrame(this, miFrames[i]);
stacks = new StackFrame[miFrames.length];
for (int i = 0; i < stacks.length; i++) {
stacks[i] = new StackFrame(this, miFrames[i]);
}
getCTarget().setCurrentThread(oldThread, false);
return stack;
} catch (MIException e) {
//throw new CDIException(e.getMessage());
//System.out.println(e);
} catch (CDIException e) {
//throw e;
//System.out.println(e);
} finally {
currentTarget.setCurrentThread(currentThread, false);
}
return stack;
if (currentFrame == null) {
for (int i = 0; i < stacks.length; i++) {
if (stacks[i].getLevel() == 0) {
currentFrame = stacks[i];
}
}
}
return stacks;
}
/**
@ -155,42 +181,48 @@ public class CThread extends CObject implements ICDIThread {
public void setCurrentStackFrame(ICDIStackFrame stackframe) throws CDIException {
if (stackframe instanceof StackFrame) {
setCurrentStackFrame((StackFrame)stackframe);
} else {
throw new CDIException("Unknown stackframe");
}
}
public void setCurrentStackFrame(StackFrame stackframe) throws CDIException {
CSession session = getCTarget().getCSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
setCurrentStackFrame(stackframe, true);
}
public void setCurrentStackFrame(StackFrame stackframe, boolean doUpdate) throws CDIException {
int frameNum = 0;
if (stackframe != null) {
frameNum = stackframe.getLevel();
}
// Check to see if we are already at this level
StackFrame current = getCurrentStackFrame();
ICDIStackFrame current = getCurrentStackFrame();
if (current != null && current.getLevel() == frameNum) {
// noop
return;
}
MIStackSelectFrame frame = factory.createMIStackSelectFrame(frameNum);
try {
Session session = (Session)getTarget().getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIStackSelectFrame frame = factory.createMIStackSelectFrame(frameNum);
// Set ourself as the current thread first.
getCTarget().setCurrentThread(this);
((Target)getTarget()).setCurrentThread(this, doUpdate);
mi.postCommand(frame);
MIInfo info = frame.getMIInfo();
if (info == null) {
throw new CDIException("No answer");
}
currentFrame = stackframe;
// Resetting threads may change the value of
// some variables like Register. Send an update
// Resetting stackframe may change the value of
// some variables like registers. Send an update
// To generate changeEvents.
RegisterManager regMgr = session.getRegisterManager();
regMgr.update();
if (doUpdate) {
RegisterManager regMgr = (RegisterManager)session.getRegisterManager();
regMgr.update();
}
} catch (MIException e) {
throw new MI2CDIException(e);
}
@ -207,7 +239,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#finish()
*/
public void finish() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().finish();
}
@ -215,6 +247,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#resume()
*/
public void resume() throws CDIException {
getTarget().setCurrentThread(this);
getTarget().resume();
}
@ -222,7 +255,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#stepInto()
*/
public void stepInto() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().stepInto();
}
@ -230,7 +263,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#stepIntoInstruction()
*/
public void stepIntoInstruction() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().stepIntoInstruction();
}
@ -238,7 +271,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#stepOver()
*/
public void stepOver() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().stepOver();
}
@ -246,7 +279,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#stepOverInstruction()
*/
public void stepOverInstruction() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().stepOverInstruction();
}
@ -254,7 +287,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#stepReturn()
*/
public void stepReturn() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().stepReturn();
}
@ -262,7 +295,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#runUntil(ICDILocation)
*/
public void runUntil(ICDILocation location) throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().runUntil(location);
}
@ -270,7 +303,7 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#suspend()
*/
public void suspend() throws CDIException {
getCTarget().setCurrentThread(this);
getTarget().setCurrentThread(this);
getTarget().suspend();
}
@ -278,8 +311,8 @@ public class CThread extends CObject implements ICDIThread {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIThread#equals(ICDIThread)
*/
public boolean equals(ICDIThread thread) {
if (thread instanceof CThread) {
CThread cthread = (CThread) thread;
if (thread instanceof Thread) {
Thread cthread = (Thread) thread;
return id == cthread.getId();
}
return super.equals(thread);

View file

@ -10,9 +10,10 @@ 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.cdi.CSession;
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.cdi.VariableManager;
import org.eclipse.cdt.debug.mi.core.cdi.VariableObject;
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;
@ -27,7 +28,7 @@ public class Value extends CObject implements ICDIValue {
Variable variable;
public Value(Variable v) {
super(v.getCTarget());
super(v.getTarget());
variable = v;
}
@ -43,7 +44,7 @@ public class Value extends CObject implements ICDIValue {
*/
public String getValueString() throws CDIException {
String result = "";
MISession mi = getCTarget().getCSession().getMISession();
MISession mi = ((Session)(getTarget().getSession())).getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarEvaluateExpression var =
factory.createMIVarEvaluateExpression(variable.getMIVar().getVarName());
@ -96,7 +97,7 @@ public class Value extends CObject implements ICDIValue {
*/
public ICDIVariable[] getVariables() throws CDIException {
Variable[] variables = null;
CSession session = getCTarget().getCSession();
Session session = (Session)(getTarget().getSession());
MISession mi = session.getMISession();
VariableManager mgr = (VariableManager)session.getVariableManager();
CommandFactory factory = mi.getCommandFactory();
@ -111,8 +112,10 @@ public class Value extends CObject implements ICDIValue {
MIVar[] vars = info.getMIVars();
variables = new Variable[vars.length];
for (int i = 0; i < vars.length; i++) {
variables[i] = mgr.createVariable(variable.getStackFrame(),
vars[i].getExp(), vars[i]);
VariableObject varObj = new VariableObject(vars[i].getExp(),
(StackFrame)variable.getStackFrame(), variable.getVariableObject().getPosition(),
variable.getVariableObject().getStackDepth());
variables[i] = mgr.createVariable(varObj, vars[i]);
}
} catch (MIException e) {

View file

@ -6,12 +6,15 @@
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.ICDIStackFrame;
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.cdi.Format;
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.cdi.VariableObject;
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.MIVarSetFormat;
@ -26,30 +29,28 @@ import org.eclipse.cdt.debug.mi.core.output.MIVarShowAttributesInfo;
public class Variable extends CObject implements ICDIVariable {
MIVar miVar;
String name;
Value value;
StackFrame stack;
VariableObject varObj;
public Variable(StackFrame stackframe, String n, MIVar v) {
super(stackframe.getCTarget());
stack = stackframe;
name = n;
public Variable(VariableObject obj, MIVar v) {
super(obj.getStackFrame().getTarget());
miVar = v;
}
StackFrame getStackFrame() {
return stack;
varObj = obj;
}
public MIVar getMIVar() {
return miVar;
}
public VariableObject getVariableObject() {
return varObj;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getName()
*/
public String getName() throws CDIException {
return name;
return varObj.getName();
}
/**
@ -80,7 +81,7 @@ public class Variable extends CObject implements ICDIVariable {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(String)
*/
public void setValue(String expression) throws CDIException {
MISession mi = getCTarget().getCSession().getMISession();
MISession mi = ((Session)(getTarget().getSession())).getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarAssign var = factory.createMIVarAssign(miVar.getVarName(), expression);
try {
@ -102,7 +103,7 @@ public class Variable extends CObject implements ICDIVariable {
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#isEditable()
*/
public boolean isEditable() throws CDIException {
MISession mi = getCTarget().getCSession().getMISession();
MISession mi = ((Session)(getTarget().getSession())).getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarShowAttributes var = factory.createMIVarShowAttributes(miVar.getVarName());
try {
@ -122,7 +123,7 @@ public class Variable extends CObject implements ICDIVariable {
*/
public void setFormat(int format) throws CDIException {
int fmt = Format.toMIFormat(format);
MISession mi = getCTarget().getCSession().getMISession();
MISession mi = ((Session)(getTarget().getSession())).getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarSetFormat var = factory.createMIVarSetFormat(miVar.getVarName(), fmt);
try {
@ -146,4 +147,12 @@ public class Variable extends CObject implements ICDIVariable {
}
return super.equals(var);
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getStackFrame()
*/
public ICDIStackFrame getStackFrame() throws CDIException {
return varObj.getStackFrame();
}
}