1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

[265181] Cleanup in the case a resume or step command fails to execute.

This commit is contained in:
Marc Khouzam 2009-02-17 16:34:28 +00:00
parent 0465eb3d20
commit 022068033d
2 changed files with 72 additions and 59 deletions

View file

@ -195,13 +195,8 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro
} }
/** @since 2.0 */ /** @since 2.0 */
public void reverseResume(IExecutionDMContext context, final RequestMonitor rm) { public void reverseResume(final IExecutionDMContext context, final RequestMonitor rm) {
if (fReverseModeEnabled && doCanResume(context)) { if (fReverseModeEnabled && doCanResume(context)) {
setResumePending(true);
// Cygwin GDB will accept commands and execute them after the step
// which is not what we want, so mark the target as unavailable
// as soon as we send a resume command.
getCache().setContextAvailable(context, false);
MIExecReverseContinue cmd = null; MIExecReverseContinue cmd = null;
if (context instanceof IContainerDMContext) { if (context instanceof IContainerDMContext) {
cmd = new MIExecReverseContinue(context); cmd = new MIExecReverseContinue(context);
@ -214,20 +209,31 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro
} }
cmd = new MIExecReverseContinue(dmc); cmd = new MIExecReverseContinue(dmc);
} }
// getConnection().queueCommand(cmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm));
setResumePending(true);
// Cygwin GDB will accept commands and execute them after the step
// which is not what we want, so mark the target as unavailable
// as soon as we send a resume command.
getCache().setContextAvailable(context, false);
// temporary // temporary
final MIExecReverseContinue finalcmd = cmd; final MIExecReverseContinue finalcmd = cmd;
final IExecutionDMContext finaldmc = context; final IExecutionDMContext finaldmc = context;
getConnection().queueCommand( getConnection().queueCommand(
new RawCommand(finaldmc, "set exec-direction reverse"), new RawCommand(finaldmc, "set exec-direction reverse"), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override @Override
public void handleSuccess() { public void handleSuccess() {
getConnection().queueCommand(finalcmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm) { getConnection().queueCommand(finalcmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override @Override
public void handleCompleted() { public void handleCompleted() {
if (!isSuccess()) {
setResumePending(false);
getCache().setContextAvailable(context, true);
}
getConnection().queueCommand( getConnection().queueCommand(
new RawCommand(finaldmc, "set exec-direction forward"), new RawCommand(finaldmc, "set exec-direction forward"), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); new DataRequestMonitor<MIInfo>(getExecutor(), rm));
} }
}); });
@ -242,7 +248,7 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro
} }
/** @since 2.0 */ /** @since 2.0 */
public void reverseStep(IExecutionDMContext context, StepType stepType, final RequestMonitor rm) { public void reverseStep(final IExecutionDMContext context, StepType stepType, final RequestMonitor rm) {
assert context != null; assert context != null;
IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class);
@ -258,9 +264,6 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro
return; return;
} }
setResumePending(true);
fReverseStepping = true;
getCache().setContextAvailable(context, false);
MICommand<MIInfo> cmd = null; MICommand<MIInfo> cmd = null;
switch(stepType) { switch(stepType) {
case STEP_INTO: case STEP_INTO:
@ -295,21 +298,31 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro
default: default:
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Given step type not supported", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Given step type not supported", null)); //$NON-NLS-1$
rm.done(); rm.done();
return;
} }
setResumePending(true);
fReverseStepping = true;
getCache().setContextAvailable(context, false);
// temporary // temporary
final MICommand<MIInfo> finalcmd = cmd; final MICommand<MIInfo> finalcmd = cmd;
final IExecutionDMContext finaldmc = context; final IExecutionDMContext finaldmc = context;
getConnection().queueCommand( getConnection().queueCommand(
new RawCommand(finaldmc, "set exec-direction reverse"), new RawCommand(finaldmc, "set exec-direction reverse"), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override @Override
public void handleSuccess() { public void handleSuccess() {
getConnection().queueCommand(finalcmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm) { getConnection().queueCommand(finalcmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override @Override
public void handleCompleted() { public void handleCompleted() {
if (!isSuccess()) {
setResumePending(false);
fReverseStepping = false;
getCache().setContextAvailable(context, true);
}
getConnection().queueCommand( getConnection().queueCommand(
new RawCommand(finaldmc, "set exec-direction forward"), new RawCommand(finaldmc, "set exec-direction forward"), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>(getExecutor(), rm)); new DataRequestMonitor<MIInfo>(getExecutor(), rm));
} }
}); });

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.dsf.debug.service.command.CommandCache;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlShutdownDMEvent; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlShutdownDMEvent;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.mi.service.command.commands.MICommand;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecContinue; import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecContinue;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecFinish; import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecFinish;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecInterrupt; import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecInterrupt;
@ -506,33 +507,38 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
return !fTerminated && fStepping; return !fTerminated && fStepping;
} }
public void resume(IExecutionDMContext context, final RequestMonitor rm) { public void resume(final IExecutionDMContext context, final RequestMonitor rm) {
assert context != null; assert context != null;
if (doCanResume(context)) { if (doCanResume(context)) {
fResumePending = true;
// Cygwin GDB will accept commands and execute them after the step
// which is not what we want, so mark the target as unavailable
// as soon as we send a resume command.
fMICommandCache.setContextAvailable(context, false);
MIExecContinue cmd = null; MIExecContinue cmd = null;
if(context instanceof IContainerDMContext) if(context instanceof IContainerDMContext) {
cmd = new MIExecContinue(context); cmd = new MIExecContinue(context);
else{ } else {
IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class);
if (dmc == null){ if (dmc == null) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Given context: " + context + " is not an execution context.", null)); //$NON-NLS-1$ //$NON-NLS-2$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Given context: " + context + " is not an execution context.", null)); //$NON-NLS-1$ //$NON-NLS-2$
rm.done(); rm.done();
return; return;
} }
cmd = new MIExecContinue(dmc);//, new String[0]); cmd = new MIExecContinue(dmc);//, new String[0]);
} }
fResumePending = true;
// Cygwin GDB will accept commands and execute them after the step
// which is not what we want, so mark the target as unavailable
// as soon as we send a resume command.
fMICommandCache.setContextAvailable(context, false);
fConnection.queueCommand( fConnection.queueCommand(
cmd, cmd,
new DataRequestMonitor<MIInfo>(getExecutor(), rm) { new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override @Override
protected void handleSuccess() { protected void handleFailure() {
rm.done(); fResumePending = false;
fMICommandCache.setContextAvailable(context, true);
super.handleFailure();
} }
} }
); );
@ -559,15 +565,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
} }
cmd = new MIExecInterrupt(dmc); cmd = new MIExecInterrupt(dmc);
} }
fConnection.queueCommand( fConnection.queueCommand(cmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm));
cmd,
new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override
protected void handleSuccess() {
rm.done();
}
}
);
} else { } else {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Given context: " + context + ", is already suspended.", null)); //$NON-NLS-1$ //$NON-NLS-2$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Given context: " + context + ", is already suspended.", null)); //$NON-NLS-1$ //$NON-NLS-2$
rm.done(); rm.done();
@ -583,7 +581,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
canResume(context, rm); canResume(context, rm);
} }
public void step(IExecutionDMContext context, StepType stepType, final RequestMonitor rm) { public void step(final IExecutionDMContext context, StepType stepType, final RequestMonitor rm) {
assert context != null; assert context != null;
IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class); IMIExecutionDMContext dmc = DMContexts.getAncestorOfType(context, IMIExecutionDMContext.class);
@ -599,18 +597,13 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
return; return;
} }
fResumePending = true; MICommand<MIInfo> cmd = null;
fStepping = true;
fMICommandCache.setContextAvailable(context, false);
switch(stepType) { switch(stepType) {
case STEP_INTO: case STEP_INTO:
fConnection.queueCommand( cmd = new MIExecStep(dmc, 1);
new MIExecStep(dmc, 1), new DataRequestMonitor<MIInfo>(getExecutor(), rm) {}
);
break; break;
case STEP_OVER: case STEP_OVER:
fConnection.queueCommand( cmd = new MIExecNext(dmc);
new MIExecNext(dmc), new DataRequestMonitor<MIInfo>(getExecutor(), rm) {});
break; break;
case STEP_RETURN: case STEP_RETURN:
// The -exec-finish command operates on the selected stack frame, but here we always // The -exec-finish command operates on the selected stack frame, but here we always
@ -622,27 +615,40 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
MIStack stackService = getServicesTracker().getService(MIStack.class); MIStack stackService = getServicesTracker().getService(MIStack.class);
if (stackService != null) { if (stackService != null) {
IFrameDMContext topFrameDmc = stackService.createFrameDMContext(dmc, 0); IFrameDMContext topFrameDmc = stackService.createFrameDMContext(dmc, 0);
fConnection.queueCommand( cmd = new MIExecFinish(topFrameDmc);
new MIExecFinish(topFrameDmc), new DataRequestMonitor<MIInfo>(getExecutor(), rm) {});
} else { } else {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Cannot create context for command, stack service not available.", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Cannot create context for command, stack service not available.", null)); //$NON-NLS-1$
rm.done(); rm.done();
return;
} }
break; break;
case INSTRUCTION_STEP_INTO: case INSTRUCTION_STEP_INTO:
fConnection.queueCommand( cmd = new MIExecStepInstruction(dmc, 1);
new MIExecStepInstruction(dmc, 1), new DataRequestMonitor<MIInfo>(getExecutor(), rm) {}
);
break; break;
case INSTRUCTION_STEP_OVER: case INSTRUCTION_STEP_OVER:
fConnection.queueCommand( cmd = new MIExecNextInstruction(dmc, 1);
new MIExecNextInstruction(dmc, 1), new DataRequestMonitor<MIInfo>(getExecutor(), rm) {}
);
break; break;
default: default:
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Given step type not supported", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Given step type not supported", null)); //$NON-NLS-1$
rm.done(); rm.done();
return;
} }
fResumePending = true;
fStepping = true;
fMICommandCache.setContextAvailable(context, false);
fConnection.queueCommand(cmd, new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
@Override
public void handleFailure() {
fResumePending = false;
fStepping = false;
fMICommandCache.setContextAvailable(context, true);
super.handleFailure();
}
});
} }
public void getExecutionContexts(final IContainerDMContext containerDmc, final DataRequestMonitor<IExecutionDMContext[]> rm) { public void getExecutionContexts(final IContainerDMContext containerDmc, final DataRequestMonitor<IExecutionDMContext[]> rm) {
@ -707,13 +713,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl, ICa
fResumePending = true; fResumePending = true;
fMICommandCache.setContextAvailable(context, false); fMICommandCache.setContextAvailable(context, false);
fConnection.queueCommand(new MIExecUntil(dmc, fileName + ":" + lineNo), //$NON-NLS-1$ fConnection.queueCommand(new MIExecUntil(dmc, fileName + ":" + lineNo), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>( new DataRequestMonitor<MIInfo>(getExecutor(), rm));
getExecutor(), rm) {
@Override
protected void handleSuccess() {
rm.done();
}
});
} else { } else {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED,
"Cannot resume given DMC.", null)); //$NON-NLS-1$ "Cannot resume given DMC.", null)); //$NON-NLS-1$