From 5f378a17517fdc8ba572771ff0426378a9f5fda6 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Tue, 1 Apr 2008 03:39:29 +0000 Subject: [PATCH] [223969] Extended DsfMemoryBlockRetrieval to support multiple contexts. --- .../dd/dsf/debug/model/DsfMemoryBlock.java | 12 ++-- .../debug/model/DsfMemoryBlockRetrieval.java | 58 +++++++++---------- .../launching/GdbLaunchDelegate.java | 4 +- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java index 3f6d22d3829..c5d800122f7 100644 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java @@ -31,6 +31,7 @@ import org.eclipse.dd.dsf.debug.internal.DsfDebugPlugin; import org.eclipse.dd.dsf.debug.service.IMemory; import org.eclipse.dd.dsf.debug.service.IRunControl; import org.eclipse.dd.dsf.debug.service.IMemory.IMemoryChangedEvent; +import org.eclipse.dd.dsf.debug.service.IMemory.IMemoryDMContext; import org.eclipse.dd.dsf.service.DsfServiceEventHandler; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; @@ -49,6 +50,7 @@ import org.eclipse.debug.core.model.MemoryByte; */ public class DsfMemoryBlock extends PlatformObject implements IMemoryBlockExtension { + private final IMemoryDMContext fContext; private final ILaunch fLaunch; private final IDebugTarget fDebugTarget; private final DsfMemoryBlockRetrieval fRetrieval; @@ -76,11 +78,11 @@ public class DsfMemoryBlock extends PlatformObject implements IMemoryBlockExtens * @param word_size - the number of bytes per address * @param length - the requested block length (could be 0) */ - DsfMemoryBlock(DsfMemoryBlockRetrieval retrieval, String modelId, String expression, BigInteger address, int word_size, long length) { - + DsfMemoryBlock(DsfMemoryBlockRetrieval retrieval, IMemoryDMContext context, String modelId, String expression, BigInteger address, int word_size, long length) { fLaunch = retrieval.getLaunch(); fDebugTarget = retrieval.getDebugTarget(); fRetrieval = retrieval; + fContext = context; fModelId = modelId; fExpression = expression; fBaseAddress = address; @@ -425,7 +427,7 @@ public class DsfMemoryBlock extends PlatformObject implements IMemoryBlockExtens if (memoryService != null) { // Go for it memoryService.getMemory( - fRetrieval.getContext(), address, 0, fWordSize, (int) length, + fContext, address, 0, fWordSize, (int) length, new DataRequestMonitor(fRetrieval.getExecutor(), drm) { @Override protected void handleSuccess() { @@ -471,7 +473,7 @@ public class DsfMemoryBlock extends PlatformObject implements IMemoryBlockExtens if (memoryService != null) { // Go for it memoryService.setMemory( - fRetrieval.getContext(), address, offset, fWordSize, bytes.length, bytes, + fContext, address, offset, fWordSize, bytes.length, bytes, new RequestMonitor(fRetrieval.getExecutor(), null)); } @@ -511,7 +513,7 @@ public class DsfMemoryBlock extends PlatformObject implements IMemoryBlockExtens public void eventDispatched(IMemoryChangedEvent e) { // Check if we are in the same address space - if (e.getDMContext().equals(fRetrieval.getContext())) { + if (e.getDMContext().equals(fContext)) { IAddress[] addresses = e.getAddresses(); for (int i = 0; i < addresses.length; i++) handleMemoryChange(addresses[i].getValue()); diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlockRetrieval.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlockRetrieval.java index 6ec2b2b5938..bc5bad8d61a 100644 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlockRetrieval.java +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlockRetrieval.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.Query; +import org.eclipse.dd.dsf.datamodel.DMContexts; import org.eclipse.dd.dsf.datamodel.IDMContext; import org.eclipse.dd.dsf.debug.internal.DsfDebugPlugin; import org.eclipse.dd.dsf.debug.service.IExpressions; @@ -78,7 +79,6 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl private final String fModelId; private final DsfSession fSession; private final DsfExecutor fExecutor; - private final IMemoryDMContext fContext; private final String fContextString; private final ServiceTracker fMemoryServiceTracker; private final ServiceTracker fExpressionServiceTracker; @@ -98,11 +98,10 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl * @param dmc * @throws DebugException */ - public DsfMemoryBlockRetrieval(String modelId, ILaunchConfiguration config, IMemoryDMContext dmc) throws DebugException { + public DsfMemoryBlockRetrieval(String modelId, ILaunchConfiguration config, DsfSession session) throws DebugException { // DSF stuff fModelId = modelId; - fContext = dmc; // FIXME: Currently memory contexts are differentiated by sessionID // so there is no way to guarantee the memory blocks will be reinstated @@ -114,10 +113,10 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl // fContextString = fContext.toString(); fContextString = "Context string"; //$NON-NLS-1$ - fSession = DsfSession.getSession(fContext.getSessionId()); + fSession = session; if (fSession == null) { throw new IllegalArgumentException( - "Session for context " + fContext + " is not active"); //$NON-NLS-1$ //$NON-NLS-2$ + "Session " + session + " is not active"); //$NON-NLS-1$ //$NON-NLS-2$ } fExecutor = fSession.getExecutor(); BundleContext bundle = DsfDebugPlugin.getBundleContext(); @@ -126,7 +125,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl // amalgamated one because it is less error prone (and we are lazy). // Create a tracker for the MemoryService - String memoryServiceFilter = DsfServices.createServiceFilter(IMemory.class, dmc.getSessionId()); + String memoryServiceFilter = DsfServices.createServiceFilter(IMemory.class, session.getId()); try { fMemoryServiceTracker = new ServiceTracker( @@ -144,7 +143,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl + IExpressions.class.getName() + ")" + //$NON-NLS-1$ "(" + IDsfService.PROP_SESSION_ID //$NON-NLS-1$ - + "=" + dmc.getSessionId() + ")" + //$NON-NLS-1$//$NON-NLS-2$ + + "=" + session.getId() + ")" + //$NON-NLS-1$//$NON-NLS-2$ ")"; //$NON-NLS-1$ try { @@ -214,7 +213,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl /** * Restore the memory monitors from the memento in the launch configuration */ - public void initialize() { + public void initialize(final IMemoryDMContext memoryCtx) { try { final String memento = fLaunchConfig.getAttribute(ATTR_DEBUGGER_MEMORY_BLOCKS, ""); //$NON-NLS-1$ if (memento != null && memento.trim().length() != 0) { @@ -222,7 +221,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl getExecutor().submit(new Runnable() { public void run() { try { - createBlocksFromConfiguration(memento); + createBlocksFromConfiguration(memoryCtx, memento); } catch (CoreException e) { DsfDebugPlugin.getDefault().getLog().log(e.getStatus()); } @@ -234,7 +233,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl } } - private void createBlocksFromConfiguration(String memento) throws CoreException { + private void createBlocksFromConfiguration(IMemoryDMContext memoryCtx, String memento) throws CoreException { // Parse the memento and validate its type Element root = DebugPlugin.parseDocument(memento); @@ -258,7 +257,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl String label = entry.getAttribute(ATTR_MEMORY_BLOCK_EXPR_LABEL); String address = entry.getAttribute(ATTR_MEMORY_BLOCK_EXPR_ADDRESS); BigInteger blockAddress = new BigInteger(address); - DsfMemoryBlock block = new DsfMemoryBlock(this, fModelId, label, blockAddress, fWordSize, 0); + DsfMemoryBlock block = new DsfMemoryBlock(this, memoryCtx, fModelId, label, blockAddress, fWordSize, 0); blocks.add(block); } } @@ -319,10 +318,6 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl return fExecutor; } - public IMemoryDMContext getContext() { - return fContext; - } - public ServiceTracker getServiceTracker() { return fMemoryServiceTracker; } @@ -375,10 +370,9 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl * long) */ public IMemoryBlock getMemoryBlock(final long startAddress, final long length) throws DebugException { - // The expression to display in the rendering tab (in hex by convention) - // Put here for the sake of completeness (not used with IMemoryBlockExtension) - String expression = "0x" + Long.toHexString(startAddress); //$NON-NLS-1$ - return new DsfMemoryBlock(this, fModelId, expression, BigInteger.valueOf(startAddress), fWordSize, length); + throw new DebugException(new Status( + IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, DebugException.NOT_SUPPORTED, + "getMemoryBlock() not supported, use getExtendedMemoryBlock()", null)); //$NON-NLS-1$ } /////////////////////////////////////////////////////////////////////////// @@ -392,7 +386,19 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl * java.lang.Object) */ public IMemoryBlockExtension getExtendedMemoryBlock(String expression, Object context) throws DebugException { + // Drill for the actual DMC + IMemoryDMContext memoryDmc = null; + if (context instanceof IAdaptable) { + IDMContext dmc = (IDMContext)((IAdaptable)context).getAdapter(IDMContext.class); + if (dmc != null) { + memoryDmc = DMContexts.getAncestorOfType(dmc, IMemoryDMContext.class); + } + } + if (memoryDmc == null) { + return null; + } + // The block start address (supports 64-bit processors) BigInteger blockAddress; @@ -427,18 +433,8 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl // try to resolve as an expression. // In case of failure, simply return 'null' - // Drill for the actual DMC - IDMContext dmc = null; - if (context instanceof IAdaptable) { - dmc = (IDMContext)((IAdaptable)context).getAdapter(IDMContext.class); - } - - if (dmc == null) { - return null; - } - // Resolve the expression - blockAddress = resolveMemoryAddress(dmc, expression); + blockAddress = resolveMemoryAddress(memoryDmc, expression); if (blockAddress == null) { return null; } @@ -457,7 +453,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl * the memory request cache should save the day. */ - return new DsfMemoryBlock(this, fModelId, expression, blockAddress, fWordSize, 0); + return new DsfMemoryBlock(this, memoryDmc, fModelId, expression, blockAddress, fWordSize, 0); } /////////////////////////////////////////////////////////////////////////// diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java index 8fbe2468cbc..20671367bfe 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java @@ -183,9 +183,9 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate GDBControl gdbControl = tracker.getService(GDBControl.class); if (gdbControl != null) { IMemoryBlockRetrieval memRetrieval = new DsfMemoryBlockRetrieval( - GDB_DEBUG_MODEL_ID, config, (IMemoryDMContext)gdbControl.getControlDMContext()); + GDB_DEBUG_MODEL_ID, config, launch.getSession()); launch.getSession().registerModelAdapter(IMemoryBlockRetrieval.class, memRetrieval); - ((DsfMemoryBlockRetrieval) memRetrieval).initialize(); + ((DsfMemoryBlockRetrieval) memRetrieval).initialize((IMemoryDMContext)gdbControl.getControlDMContext()); } tracker.dispose(); return null;