From 5ac30e181b3bc5ad7fa5faf6be7aee40bbc81491 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Thu, 27 Mar 2008 19:07:07 +0000 Subject: [PATCH] [223969] Extended CommanCache to track multiple contexts as "available". --- .../debug/service/command/CommandCache.java | 52 ++++++++++--------- .../examples/pda/service/PDAExpressions.java | 4 +- .../dd/examples/pda/service/PDAStack.java | 4 +- .../dd/mi/service/ExpressionService.java | 4 +- .../org/eclipse/dd/mi/service/MIMemory.java | 12 ++--- .../eclipse/dd/mi/service/MIRegisters.java | 4 +- .../eclipse/dd/mi/service/MIRunControl.java | 12 ++--- 7 files changed, 48 insertions(+), 44 deletions(-) diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java index fb3e2935160..7b7f91ddbf5 100644 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java @@ -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 cmd, DataRequestMonitor rm ) { - fCmdStyle = cmdstyle; fCommand = cmd; fCurrentRequestMonitors = new LinkedList>(); 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 fAvailableContexts = new HashSet(); 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 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 command) { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java index 7e0e4236b32..3ebafb920b8 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java @@ -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(); } } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java index 5f4648414dc..6fe86364277 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java @@ -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(); } } diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/ExpressionService.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/ExpressionService.java index 5a085191629..2db9093e88a 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/ExpressionService.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/ExpressionService.java @@ -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(); } diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIMemory.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIMemory.java index 0870b86f01a..1296edaf1a5 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIMemory.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIMemory.java @@ -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); } /** diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRegisters.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRegisters.java index a7c658569ad..222464175d2 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRegisters.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRegisters.java @@ -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(); } diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRunControl.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRunControl.java index a70af84f3be..31481a48b4c 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRunControl.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/MIRunControl.java @@ -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( getExecutor(), rm) {