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

[223969] Extended CommanCache to track multiple contexts as "available".

This commit is contained in:
Pawel Piech 2008-03-27 19:07:07 +00:00
parent 8c8a9fddff
commit 5ac30e181b
7 changed files with 48 additions and 44 deletions

View file

@ -14,10 +14,12 @@ package org.eclipse.dd.dsf.debug.service.command;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@ -63,17 +65,12 @@ public class CommandCache implements ICommandListener
/** Command being processed for this command */
CommandInfo fCoalescedCmd;
/** No longer really used and needs to be deleted */
int fResetCounterStatus;
public CommandInfo( CommandStyle cmdstyle, ICommand<ICommandResult> cmd, DataRequestMonitor<ICommandResult> rm ) {
fCmdStyle = cmdstyle;
fCommand = cmd;
fCurrentRequestMonitors = new LinkedList<DataRequestMonitor<ICommandResult>>();
fCurrentRequestMonitors.add(rm);
fCoalescedCmd = null;
fResetCounterStatus = fResetCounter;
}
public CommandStyle getCommandstyle() { return fCmdStyle; }
@ -92,7 +89,7 @@ public class CommandCache implements ICommandListener
@Override
public int hashCode() {
return (fCommand.hashCode()+ (fResetCounterStatus + 1));
return fCommand.hashCode();
}
}
@ -143,8 +140,7 @@ public class CommandCache implements ICommandListener
* when back into individual results from this command.
*/
private boolean fIsTargetAvailable = true;
private int fResetCounter = 0;
private Set<IDMContext> fAvailableContexts = new HashSet<IDMContext>();
private ICommandControl fCommandControl;
@ -267,7 +263,7 @@ public class CommandCache implements ICommandListener
/*
* Return an error if the target is available anymore.
*/
if (!fIsTargetAvailable) {
if (!isTargetAvailable(command.getContext())) {
rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, IDsfStatusConstants.INVALID_STATE, "Target not available.", null)); //$NON-NLS-1$
rm.done();
return;
@ -440,33 +436,41 @@ public class CommandCache implements ICommandListener
}
/**
* Sets the cache to a state in which target access is not allowed.
* When target is not available, commands to the target will either
* return data that is found in the cache already, or will return an
* error. This is useful in avoiding sending commands to target when
* they are known to fail or return unreliable results, while still
* providing access to the cached data.
*
* @param isAvailable Flag indicating whether target can be accessed.
* TODO
*/
public void setTargetAvailable(boolean isAvailable) {
fIsTargetAvailable = isAvailable;
public void setContextAvailable(IDMContext context, boolean isAvailable) {
if (isAvailable) {
fAvailableContexts.add(context);
} else {
fAvailableContexts.remove(context);
for (Iterator<IDMContext> itr = fAvailableContexts.iterator(); itr.hasNext();) {
if (DMContexts.isAncestorOf(itr.next(), context)) {
itr.remove();
}
}
}
}
/**
* Retrieves current flag indicating target availability.
* @see #setTargetAvailable(boolean)
* TODO
* @see #setContextAvailable(IDMContext, boolean)
*/
public boolean isTargetAvailable() {
return fIsTargetAvailable;
public boolean isTargetAvailable(IDMContext context) {
for (IDMContext availableContext : fAvailableContexts) {
if (context.equals(availableContext) || DMContexts.isAncestorOf(context, availableContext)) {
return true;
}
}
return false;
}
/**
* Clears the cache data.
*/
public void reset() {
fCachedContexts.clear();
fResetCounter++;
}
public void commandRemoved(ICommand<? extends ICommandResult> command) {

View file

@ -357,7 +357,7 @@ public class PDAExpressions extends AbstractDsfService implements IExpressions {
public void eventDispatched(IResumedDMEvent e) {
// Mark the cache as not available, so that data retrieval commands
// will fail. Also reset the cache unless it was a step command.
fCommandCache.setTargetAvailable(false);
fCommandCache.setContextAvailable(e.getDMContext(), false);
if (!e.getReason().equals(StateChangeReason.STEP)) {
fCommandCache.reset();
}
@ -367,7 +367,7 @@ public class PDAExpressions extends AbstractDsfService implements IExpressions {
@DsfServiceEventHandler
public void eventDispatched(ISuspendedDMEvent e) {
// Enable sending commands to target and clear the cache.
fCommandCache.setTargetAvailable(true);
fCommandCache.setContextAvailable(e.getDMContext(), true);
fCommandCache.reset();
}
}

View file

@ -364,7 +364,7 @@ public class PDAStack extends AbstractDsfService implements IStack {
public void eventDispatched(IResumedDMEvent e) {
// Mark the cache as not available, so that stack commands will
// fail. Also reset the cache unless it was a step command.
fCommandCache.setTargetAvailable(false);
fCommandCache.setContextAvailable(e.getDMContext(), false);
if (!e.getReason().equals(StateChangeReason.STEP)) {
fCommandCache.reset();
}
@ -374,7 +374,7 @@ public class PDAStack extends AbstractDsfService implements IStack {
@DsfServiceEventHandler
public void eventDispatched(ISuspendedDMEvent e) {
// Enable sending commands to target and clear the cache.
fCommandCache.setTargetAvailable(true);
fCommandCache.setContextAvailable(e.getDMContext(), true);
fCommandCache.reset();
}
}

View file

@ -884,7 +884,7 @@ public class ExpressionService extends AbstractDsfService implements IExpression
@DsfServiceEventHandler
public void eventDispatched(IRunControl.IResumedDMEvent e) {
fExpressionCache.setTargetAvailable(false);
fExpressionCache.setContextAvailable(e.getDMContext(), false);
if (e.getReason() != StateChangeReason.STEP) {
fExpressionCache.reset();
}
@ -892,7 +892,7 @@ public class ExpressionService extends AbstractDsfService implements IExpression
@DsfServiceEventHandler
public void eventDispatched(IRunControl.ISuspendedDMEvent e) {
fExpressionCache.setTargetAvailable(true);
fExpressionCache.setContextAvailable(e.getDMContext(), true);
fExpressionCache.reset();
}

View file

@ -280,7 +280,7 @@ public class MIMemory extends AbstractDsfService implements IMemory {
@DsfServiceEventHandler
public void eventDispatched(IRunControl.IResumedDMEvent e) {
fMemoryCache.setTargetAvailable(false);
fMemoryCache.setTargetAvailable(e.getDMContext(), false);
if (e.getReason() != StateChangeReason.STEP) {
fMemoryCache.reset();
}
@ -288,7 +288,7 @@ public class MIMemory extends AbstractDsfService implements IMemory {
@DsfServiceEventHandler
public void eventDispatched(IRunControl.ISuspendedDMEvent e) {
fMemoryCache.setTargetAvailable(true);
fMemoryCache.setTargetAvailable(e.getDMContext(), true);
fMemoryCache.reset();
}
@ -450,12 +450,12 @@ public class MIMemory extends AbstractDsfService implements IMemory {
fMemoryBlockList.clear();
}
public void setTargetAvailable(boolean isAvailable) {
fCommandCache.setTargetAvailable(isAvailable);
public void setTargetAvailable(IDMContext dmc, boolean isAvailable) {
fCommandCache.setContextAvailable(dmc, isAvailable);
}
public boolean isTargetAvailable() {
return fCommandCache.isTargetAvailable();
public boolean isTargetAvailable(IDMContext dmc) {
return fCommandCache.isTargetAvailable(dmc);
}
/**

View file

@ -397,7 +397,7 @@ public class MIRegisters extends AbstractDsfService implements IRegisters {
*/
@DsfServiceEventHandler public void eventDispatched(IRunControl.IResumedDMEvent e) {
fRegisterValueCache.setTargetAvailable(false);
fRegisterValueCache.setContextAvailable(e.getDMContext(), false);
if (e.getReason() != StateChangeReason.STEP) {
fRegisterValueCache.reset();
}
@ -405,7 +405,7 @@ public class MIRegisters extends AbstractDsfService implements IRegisters {
@DsfServiceEventHandler public void eventDispatched(
IRunControl.ISuspendedDMEvent e) {
fRegisterValueCache.setTargetAvailable(true);
fRegisterValueCache.setContextAvailable(e.getDMContext(), true);
fRegisterValueCache.reset();
}

View file

@ -394,7 +394,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
fSuspended = false;
fResumePending = false;
fStateChangeReason = e.getReason();
fMICommandCache.setTargetAvailable(false);
fMICommandCache.setContextAvailable(e.getDMContext(), false);
//fStateChangeTriggeringContext = e.getTriggeringContext();
if (e.getReason().equals(StateChangeReason.STEP)) {
fStepping = true;
@ -406,8 +406,8 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
@DsfServiceEventHandler
public void eventDispatched(ContainerSuspendedEvent e) {
fMICommandCache.setTargetAvailable(true);
fMICommandCache.reset();
fMICommandCache.setContextAvailable(e.getDMContext(), true);
fMICommandCache.reset(e.getDMContext());
fStateChangeReason = e.getReason();
fStateChangeTriggeringContext = e.getTriggeringContext();
fSuspended = true;
@ -467,7 +467,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
// 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.setTargetAvailable(false);
fMICommandCache.setContextAvailable(context, false);
MIExecContinue cmd = null;
if(context instanceof IContainerDMContext)
cmd = new MIExecContinue(context);
@ -549,7 +549,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
fResumePending = true;
fStepping = true;
fMICommandCache.setTargetAvailable(false);
fMICommandCache.setContextAvailable(context, false);
switch(stepType) {
case STEP_INTO:
fConnection.queueCommand(
@ -649,7 +649,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
if (canResume(context)) {
fResumePending = true;
fMICommandCache.setTargetAvailable(false);
fMICommandCache.setContextAvailable(context, false);
fConnection.queueCommand(new MIExecUntil(dmc, fileName + ":" + lineNo), //$NON-NLS-1$
new DataRequestMonitor<MIInfo>(
getExecutor(), rm) {