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

suspendedInferior() resumeInferior() takes ICDITarget

as argument.
This commit is contained in:
Alain Magloire 2003-01-31 19:54:10 +00:00
parent d949b6306c
commit c5814d87bb

View file

@ -77,65 +77,59 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
boolean hasBreakpointChanged(Breakpoint point, MIBreakpoint miBreakpoint) { boolean hasBreakpointChanged(Breakpoint point, MIBreakpoint miBreakpoint) {
boolean changed = false; boolean changed = false;
if (point != null) { MIBreakpoint miBreak = point.getMIBreakpoint();
MIBreakpoint miBreak = point.getMIBreakpoint(); return miBreak.isEnabled() != miBreakpoint.isEnabled() ||
changed = (miBreak.isEnabled() != miBreakpoint.isEnabled()) || !miBreak.getCondition().equals(miBreakpoint.getCondition()) ||
!miBreak.getCondition().equals(miBreakpoint.getCondition()) || miBreak.getIgnoreCount() != miBreakpoint.getIgnoreCount();
(miBreak.getIgnoreCount() != miBreakpoint.getIgnoreCount());
}
return changed;
} }
public Breakpoint getBreakpoint(int number) { public Breakpoint getBreakpoint(int number) {
ICDIBreakpoint[] bkpts = listBreakpoints(); Breakpoint[] bkpts = (Breakpoint[]) breakList.toArray(new Breakpoint[0]);;
for (int i = 0; i < bkpts.length; i++) { for (int i = 0; i < bkpts.length; i++) {
if (bkpts[i] instanceof Breakpoint) { MIBreakpoint miBreak = bkpts[i].getMIBreakpoint();
Breakpoint point = (Breakpoint) bkpts[i]; if (miBreak.getNumber() == number) {
MIBreakpoint miBreak = point.getMIBreakpoint(); return bkpts[i];
if (miBreak.getNumber() == number) {
return point;
}
} }
} }
return null; return null;
} }
Watchpoint getWatchpoint(int number) { public Watchpoint getWatchpoint(int number) {
return (Watchpoint)getBreakpoint(number); return (Watchpoint)getBreakpoint(number);
} }
Breakpoint[] listBreakpoints() { boolean suspendInferior(ICDITarget target) throws CDIException {
return (Breakpoint[]) breakList.toArray(new Breakpoint[0]);
}
boolean suspendInferior() throws CDIException {
boolean shouldRestart = false; boolean shouldRestart = false;
Session s = (Session)getSession(); Session session = (Session)getSession();
ICDITarget currentTarget = s.getCurrentTarget(); // Stop the program
// Stop the program and disable events. if (allowInterrupt) {
if (currentTarget instanceof Target) { if (target instanceof Target) {
Target target = (Target)currentTarget; Target ctarget = (Target)target;
if (target.isRunning() && allowInterrupt) { // Disable events.
int lastToken = target.getLastExecutionToken(); if (ctarget.isRunning()) {
shouldRestart = true; EventManager mgr = (EventManager)session.getEventManager();
((EventManager)s.getEventManager()).disableEventToken(lastToken); int lastToken = ctarget.getLastExecutionToken();
mgr.disableEventToken(lastToken);
ctarget.suspend();
shouldRestart = true;
mgr.enableEventToken(lastToken);
}
} else if (!target.isSuspended()) {
target.suspend(); target.suspend();
((EventManager)s.getEventManager()).enableEventToken(lastToken); shouldRestart = true;
} }
} }
return shouldRestart; return shouldRestart;
} }
void resumeInferior(boolean shouldRestart) throws CDIException { void resumeInferior(ICDITarget target, boolean shouldRestart) throws CDIException {
if (shouldRestart) { if (shouldRestart) {
Session s = (Session)getSession();
ICDITarget target = s.getCurrentTarget();
target.resume(); target.resume();
} }
} }
public void deleteBreakpoint (int no) { public void deleteBreakpoint (int no) {
Breakpoint[] points = listBreakpoints(); Breakpoint[] points = (Breakpoint[]) breakList.toArray(new Breakpoint[0]);;
for (int i = 0; i < points.length; i++) { for (int i = 0; i < points.length; i++) {
if (points[i].getMIBreakpoint().getNumber() == no) { if (points[i].getMIBreakpoint().getNumber() == no) {
breakList.remove(points[i]); breakList.remove(points[i]);
@ -152,12 +146,12 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} else { } else {
throw new CDIException("Not a CDT breakpoint"); throw new CDIException("Not a CDT breakpoint");
} }
boolean state = suspendInferior(); boolean state = suspendInferior(breakpoint.getTarget());
Session s = (Session)getSession(); Session session = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory(); CommandFactory factory = session.getMISession().getCommandFactory();
MIBreakEnable breakEnable = factory.createMIBreakEnable(new int[] { number }); MIBreakEnable breakEnable = factory.createMIBreakEnable(new int[] { number });
try { try {
s.getMISession().postCommand(breakEnable); session.getMISession().postCommand(breakEnable);
MIInfo info = breakEnable.getMIInfo(); MIInfo info = breakEnable.getMIInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
@ -166,11 +160,11 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
// Resume the program and enable events. // Resume the program and enable events.
resumeInferior(state); resumeInferior(breakpoint.getTarget(), state);
} }
((Breakpoint) breakpoint).getMIBreakpoint().setEnabled(true); ((Breakpoint) breakpoint).getMIBreakpoint().setEnabled(true);
// Fire a changed Event. // Fire a changed Event.
MISession mi = s.getMISession(); MISession mi = session.getMISession();
mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber())); mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber()));
} }
@ -182,13 +176,14 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} else { } else {
throw new CDIException("Not a CDT breakpoint"); throw new CDIException("Not a CDT breakpoint");
} }
boolean state = suspendInferior();
Session s = (Session)getSession(); Session session = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory(); boolean state = suspendInferior(breakpoint.getTarget());
CommandFactory factory = session.getMISession().getCommandFactory();
MIBreakDisable breakDisable = MIBreakDisable breakDisable =
factory.createMIBreakDisable(new int[] { number }); factory.createMIBreakDisable(new int[] { number });
try { try {
s.getMISession().postCommand(breakDisable); session.getMISession().postCommand(breakDisable);
MIInfo info = breakDisable.getMIInfo(); MIInfo info = breakDisable.getMIInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
@ -196,11 +191,11 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
resumeInferior(state); resumeInferior(breakpoint.getTarget(), state);
} }
((Breakpoint) breakpoint).getMIBreakpoint().setEnabled(false); ((Breakpoint) breakpoint).getMIBreakpoint().setEnabled(false);
// Fire a changed Event. // Fire a changed Event.
MISession mi = s.getMISession(); MISession mi = session.getMISession();
mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber())); mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber()));
} }
@ -213,9 +208,9 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
throw new CDIException("Not a CDT breakpoint"); throw new CDIException("Not a CDT breakpoint");
} }
boolean state = suspendInferior(); Session session = (Session)getSession();
Session s = (Session)getSession(); boolean state = suspendInferior(breakpoint.getTarget());
CommandFactory factory = s.getMISession().getCommandFactory(); CommandFactory factory = session.getMISession().getCommandFactory();
// reset the values to sane states. // reset the values to sane states.
String exprCond = condition.getExpression(); String exprCond = condition.getExpression();
@ -230,14 +225,14 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
try { try {
MIBreakCondition breakCondition = MIBreakCondition breakCondition =
factory.createMIBreakCondition(number, exprCond); factory.createMIBreakCondition(number, exprCond);
s.getMISession().postCommand(breakCondition); session.getMISession().postCommand(breakCondition);
MIInfo info = breakCondition.getMIInfo(); MIInfo info = breakCondition.getMIInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
} }
MIBreakAfter breakAfter = MIBreakAfter breakAfter =
factory.createMIBreakAfter(number, ignoreCount); factory.createMIBreakAfter(number, ignoreCount);
s.getMISession().postCommand(breakAfter); session.getMISession().postCommand(breakAfter);
info = breakAfter.getMIInfo(); info = breakAfter.getMIInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
@ -245,10 +240,10 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
resumeInferior(state); resumeInferior(breakpoint.getTarget(), state);
} }
// Fire a changed Event. // Fire a changed Event.
MISession mi = s.getMISession(); MISession mi = session.getMISession();
mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber())); mi.fireEvent(new MIBreakpointChangedEvent(((Breakpoint)breakpoint).getMIBreakpoint().getNumber()));
} }
@ -278,7 +273,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} }
} }
// Check if any breakpoint was removed. // Check if any breakpoint was removed.
Breakpoint[] oldBreakpoints = listBreakpoints(); Breakpoint[] oldBreakpoints = (Breakpoint[]) breakList.toArray(new Breakpoint[0]);
for (int i = 0; i < oldBreakpoints.length; i++) { for (int i = 0; i < oldBreakpoints.length; i++) {
boolean found = false; boolean found = false;
int no = oldBreakpoints[i].getMIBreakpoint().getNumber(); int no = oldBreakpoints[i].getMIBreakpoint().getNumber();
@ -309,7 +304,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteAllBreakpoints() * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#deleteAllBreakpoints()
*/ */
public void deleteAllBreakpoints() throws CDIException { public void deleteAllBreakpoints() throws CDIException {
deleteBreakpoints(listBreakpoints()); deleteBreakpoints(getBreakpoints());
} }
/** /**
@ -333,12 +328,12 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
throw new CDIException("Not a CDT breakpoint"); throw new CDIException("Not a CDT breakpoint");
} }
} }
boolean state = suspendInferior(); Session session = (Session)getSession();
Session s = (Session)getSession(); boolean state = suspendInferior(session.getCurrentTarget());
CommandFactory factory = s.getMISession().getCommandFactory(); CommandFactory factory = session.getMISession().getCommandFactory();
MIBreakDelete breakDelete = factory.createMIBreakDelete(numbers); MIBreakDelete breakDelete = factory.createMIBreakDelete(numbers);
try { try {
s.getMISession().postCommand(breakDelete); session.getMISession().postCommand(breakDelete);
MIInfo info = breakDelete.getMIInfo(); MIInfo info = breakDelete.getMIInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
@ -346,14 +341,14 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
resumeInferior(state); resumeInferior(session.getCurrentTarget(), state);
} }
List eventList = new ArrayList(breakpoints.length); List eventList = new ArrayList(breakpoints.length);
for (int i = 0; i < breakpoints.length; i++) { for (int i = 0; i < breakpoints.length; i++) {
int no = ((Breakpoint)breakpoints[i]).getMIBreakpoint().getNumber(); int no = ((Breakpoint)breakpoints[i]).getMIBreakpoint().getNumber();
eventList.add(new MIBreakpointDeletedEvent(no)); eventList.add(new MIBreakpointDeletedEvent(no));
} }
MISession mi = s.getMISession(); MISession mi = session.getMISession();
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]); MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);
mi.fireEvents(events); mi.fireEvents(events);
} }
@ -362,37 +357,9 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#getBreakpoints() * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#getBreakpoints()
*/ */
public ICDIBreakpoint[] getBreakpoints() throws CDIException { public ICDIBreakpoint[] getBreakpoints() throws CDIException {
update();
return (ICDIBreakpoint[]) breakList.toArray(new ICDIBreakpoint[0]); return (ICDIBreakpoint[]) breakList.toArray(new ICDIBreakpoint[0]);
} }
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#getBreakpoints()
*/
// public ICDIBreakpoint[] getBreakpoints() throws CDIException {
// Session s = getCSession();
// CommandFactory factory = s.getMISession().getCommandFactory();
// MIBreakList breakpointList = factory.createMIBreakList();
// try {
// s.getMISession().postCommand(breakpointList);
// MIBreakListInfo info = breakpointList.getMIBreakListInfo();
// if (info == null) {
// throw new CDIException("No answer");
// }
// MIBreakpoint[] mipoints = info.getBreakpoints();
// for (int i = 0; i < miPoints.length; i++) {
// if (!containsBreakpoint(miPoints[i].getNumber())) {
// // FIXME: Generate a Create/Change Event??
// breakList.add(new Breakpoint(this, miPoints[i]));
// }
// }
// // FIXME: Generate a DestroyEvent for deleted ones.
// } catch (MIException e) {
// throw new MI2CDIException(e);
// }
// return (ICDIBreakpoint[]) listBreakpoints();
// }
/** /**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#setCatchpoint(int, ICDICatchEvent, String, ICDICondition, boolean) * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#setCatchpoint(int, ICDICatchEvent, String, ICDICondition, boolean)
*/ */
@ -404,7 +371,7 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
/** /**
* @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#setLocationBreakpoint(int, ICDILocation, ICDICondition, boolean, String) * @see org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager#setLocationBreakpoint(int, ICDILocation, ICDICondition, boolean, String)
*/ */
public ICDILocationBreakpoint setLocationBreakpoint( int type, ICDILocation location, public ICDILocationBreakpoint setLocationBreakpoint(int type, ICDILocation location,
ICDICondition condition, String threadId) throws CDIException { ICDICondition condition, String threadId) throws CDIException {
boolean hardware = (type == ICDIBreakpoint.HARDWARE); boolean hardware = (type == ICDIBreakpoint.HARDWARE);
@ -436,15 +403,15 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} }
} }
boolean state = suspendInferior(); Session session = (Session)getSession();
Session s = (Session)getSession(); boolean state = suspendInferior(session.getCurrentTarget());
CommandFactory factory = s.getMISession().getCommandFactory(); CommandFactory factory = session.getMISession().getCommandFactory();
MIBreakInsert breakInsert = MIBreakInsert breakInsert =
factory.createMIBreakInsert( temporary, hardware, exprCond, factory.createMIBreakInsert( temporary, hardware, exprCond,
ignoreCount, line.toString()); ignoreCount, line.toString());
MIBreakpoint[] points = null; MIBreakpoint[] points = null;
try { try {
s.getMISession().postCommand(breakInsert); session.getMISession().postCommand(breakInsert);
MIBreakInsertInfo info = breakInsert.getMIBreakInsertInfo(); MIBreakInsertInfo info = breakInsert.getMIBreakInsertInfo();
if (info == null) { if (info == null) {
throw new CDIException("No answer"); throw new CDIException("No answer");
@ -456,13 +423,13 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
resumeInferior(state); resumeInferior(session.getCurrentTarget(), state);
} }
Breakpoint bkpt = new Breakpoint(this, points[0]); Breakpoint bkpt = new Breakpoint(this, points[0]);
breakList.add(bkpt); breakList.add(bkpt);
// Fire a created Event. // Fire a created Event.
MISession mi = s.getMISession(); MISession mi = session.getMISession();
mi.fireEvent(new MIBreakpointCreatedEvent(bkpt.getMIBreakpoint().getNumber())); mi.fireEvent(new MIBreakpointCreatedEvent(bkpt.getMIBreakpoint().getNumber()));
return bkpt; return bkpt;
} }
@ -476,14 +443,15 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
(watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ ); (watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ );
boolean read = ( !((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE) && boolean read = ( !((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE) &&
(watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ ); (watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ );
boolean state = suspendInferior();
Session s = (Session)getSession(); Session session = (Session)getSession();
CommandFactory factory = s.getMISession().getCommandFactory(); boolean state = suspendInferior(session.getCurrentTarget());
CommandFactory factory = session.getMISession().getCommandFactory();
MIBreakWatch breakWatch = MIBreakWatch breakWatch =
factory.createMIBreakWatch(access, read, expression); factory.createMIBreakWatch(access, read, expression);
MIBreakpoint[] points = null; MIBreakpoint[] points = null;
try { try {
s.getMISession().postCommand(breakWatch); session.getMISession().postCommand(breakWatch);
MIBreakWatchInfo info = breakWatch.getMIBreakWatchInfo(); MIBreakWatchInfo info = breakWatch.getMIBreakWatchInfo();
points = info.getMIBreakpoints(); points = info.getMIBreakpoints();
if (info == null) { if (info == null) {
@ -495,13 +463,13 @@ public class BreakpointManager extends SessionObject implements ICDIBreakpointMa
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
resumeInferior(state); resumeInferior(session.getCurrentTarget(), state);
} }
Watchpoint bkpt = new Watchpoint(this, points[0]); Watchpoint bkpt = new Watchpoint(this, points[0]);
breakList.add(bkpt); breakList.add(bkpt);
// Fire a created Event. // Fire a created Event.
MISession mi = s.getMISession(); MISession mi = session.getMISession();
mi.fireEvent(new MIBreakpointCreatedEvent(bkpt.getMIBreakpoint().getNumber())); mi.fireEvent(new MIBreakpointCreatedEvent(bkpt.getMIBreakpoint().getNumber()));
return bkpt; return bkpt;
} }