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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -63,17 +65,12 @@ public class CommandCache implements ICommandListener
/** Command being processed for this command */ /** Command being processed for this command */
CommandInfo fCoalescedCmd; CommandInfo fCoalescedCmd;
/** No longer really used and needs to be deleted */
int fResetCounterStatus;
public CommandInfo( CommandStyle cmdstyle, ICommand<ICommandResult> cmd, DataRequestMonitor<ICommandResult> rm ) { public CommandInfo( CommandStyle cmdstyle, ICommand<ICommandResult> cmd, DataRequestMonitor<ICommandResult> rm ) {
fCmdStyle = cmdstyle; fCmdStyle = cmdstyle;
fCommand = cmd; fCommand = cmd;
fCurrentRequestMonitors = new LinkedList<DataRequestMonitor<ICommandResult>>(); fCurrentRequestMonitors = new LinkedList<DataRequestMonitor<ICommandResult>>();
fCurrentRequestMonitors.add(rm); fCurrentRequestMonitors.add(rm);
fCoalescedCmd = null; fCoalescedCmd = null;
fResetCounterStatus = fResetCounter;
} }
public CommandStyle getCommandstyle() { return fCmdStyle; } public CommandStyle getCommandstyle() { return fCmdStyle; }
@ -92,7 +89,7 @@ public class CommandCache implements ICommandListener
@Override @Override
public int hashCode() { 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. * when back into individual results from this command.
*/ */
private boolean fIsTargetAvailable = true; private Set<IDMContext> fAvailableContexts = new HashSet<IDMContext>();
private int fResetCounter = 0;
private ICommandControl fCommandControl; private ICommandControl fCommandControl;
@ -267,7 +263,7 @@ public class CommandCache implements ICommandListener
/* /*
* Return an error if the target is available anymore. * 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.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, IDsfStatusConstants.INVALID_STATE, "Target not available.", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
@ -440,33 +436,41 @@ public class CommandCache implements ICommandListener
} }
/** /**
* Sets the cache to a state in which target access is not allowed. * TODO
* 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.
*/ */
public void setTargetAvailable(boolean isAvailable) { public void setContextAvailable(IDMContext context, boolean isAvailable) {
fIsTargetAvailable = 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. * TODO
* @see #setTargetAvailable(boolean) * @see #setContextAvailable(IDMContext, boolean)
*/ */
public boolean isTargetAvailable() { public boolean isTargetAvailable(IDMContext context) {
return fIsTargetAvailable; for (IDMContext availableContext : fAvailableContexts) {
if (context.equals(availableContext) || DMContexts.isAncestorOf(context, availableContext)) {
return true;
} }
}
return false;
}
/** /**
* Clears the cache data. * Clears the cache data.
*/ */
public void reset() { public void reset() {
fCachedContexts.clear(); fCachedContexts.clear();
fResetCounter++;
} }
public void commandRemoved(ICommand<? extends ICommandResult> command) { 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) { public void eventDispatched(IResumedDMEvent e) {
// Mark the cache as not available, so that data retrieval commands // Mark the cache as not available, so that data retrieval commands
// will fail. Also reset the cache unless it was a step command. // 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)) { if (!e.getReason().equals(StateChangeReason.STEP)) {
fCommandCache.reset(); fCommandCache.reset();
} }
@ -367,7 +367,7 @@ public class PDAExpressions extends AbstractDsfService implements IExpressions {
@DsfServiceEventHandler @DsfServiceEventHandler
public void eventDispatched(ISuspendedDMEvent e) { public void eventDispatched(ISuspendedDMEvent e) {
// Enable sending commands to target and clear the cache. // Enable sending commands to target and clear the cache.
fCommandCache.setTargetAvailable(true); fCommandCache.setContextAvailable(e.getDMContext(), true);
fCommandCache.reset(); fCommandCache.reset();
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -394,7 +394,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
fSuspended = false; fSuspended = false;
fResumePending = false; fResumePending = false;
fStateChangeReason = e.getReason(); fStateChangeReason = e.getReason();
fMICommandCache.setTargetAvailable(false); fMICommandCache.setContextAvailable(e.getDMContext(), false);
//fStateChangeTriggeringContext = e.getTriggeringContext(); //fStateChangeTriggeringContext = e.getTriggeringContext();
if (e.getReason().equals(StateChangeReason.STEP)) { if (e.getReason().equals(StateChangeReason.STEP)) {
fStepping = true; fStepping = true;
@ -406,8 +406,8 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
@DsfServiceEventHandler @DsfServiceEventHandler
public void eventDispatched(ContainerSuspendedEvent e) { public void eventDispatched(ContainerSuspendedEvent e) {
fMICommandCache.setTargetAvailable(true); fMICommandCache.setContextAvailable(e.getDMContext(), true);
fMICommandCache.reset(); fMICommandCache.reset(e.getDMContext());
fStateChangeReason = e.getReason(); fStateChangeReason = e.getReason();
fStateChangeTriggeringContext = e.getTriggeringContext(); fStateChangeTriggeringContext = e.getTriggeringContext();
fSuspended = true; fSuspended = true;
@ -467,7 +467,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
// Cygwin GDB will accept commands and execute them after the step // Cygwin GDB will accept commands and execute them after the step
// which is not what we want, so mark the target as unavailable // which is not what we want, so mark the target as unavailable
// as soon as we send a resume command. // as soon as we send a resume command.
fMICommandCache.setTargetAvailable(false); 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);
@ -549,7 +549,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
fResumePending = true; fResumePending = true;
fStepping = true; fStepping = true;
fMICommandCache.setTargetAvailable(false); fMICommandCache.setContextAvailable(context, false);
switch(stepType) { switch(stepType) {
case STEP_INTO: case STEP_INTO:
fConnection.queueCommand( fConnection.queueCommand(
@ -649,7 +649,7 @@ public class MIRunControl extends AbstractDsfService implements IRunControl
if (canResume(context)) { if (canResume(context)) {
fResumePending = true; fResumePending = true;
fMICommandCache.setTargetAvailable(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) {