From 599aa1dbb788935616c51a56c0fe20021ce1b348 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Mon, 18 Jun 2007 17:07:19 +0000 Subject: [PATCH] Committed patch with initial memory service implementation (bug 160046). --- .../dd/dsf/debug/model/DsfMemoryBlock.java | 75 ++++++++++++++++++ .../debug/model/DsfMemoryBlockRetrieval.java | 77 ++++++++++++++++--- 2 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java 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 new file mode 100644 index 00000000000..9a7e71897fe --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/model/DsfMemoryBlock.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.dsf.debug.model; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.dd.dsf.debug.DsfDebugPlugin; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IMemoryBlock; + +public class DsfMemoryBlock extends PlatformObject implements IMemoryBlock +{ + private final DsfMemoryBlockRetrieval fRetrieval; + private final String fModelId; + private final long fStartAddress; + private final byte[] fBytes; + + DsfMemoryBlock(DsfMemoryBlockRetrieval retrieval, String modelId, long startAddress, byte[] bytes) { + fRetrieval = retrieval; + fModelId = modelId; + fStartAddress = startAddress; + fBytes = bytes; + } + + public byte[] getBytes() throws DebugException { + return fBytes; + } + + public long getLength() { + return fBytes.length; + } + + public long getStartAddress() { + return fStartAddress; + } + + public void setValue(long offset, byte[] bytes) throws DebugException { + throw new DebugException(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, DebugException.NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ + } + + public boolean supportsValueModification() { + return false; + } + + public IDebugTarget getDebugTarget() { + return null; + } + + public ILaunch getLaunch() { + return null; + } + + public String getModelIdentifier() { + return fModelId; + } + + @Override + public Object getAdapter(Class adapter) { + if (adapter.isAssignableFrom(DsfMemoryBlockRetrieval.class)) { + return fRetrieval; + } + return super.getAdapter(adapter); + } +} 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 ffd9d525696..d6418bb0aa9 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 @@ -10,40 +10,93 @@ *******************************************************************************/ package org.eclipse.dd.dsf.debug.model; +import java.util.concurrent.ExecutionException; + +import org.eclipse.cdt.utils.Addr32; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +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.concurrent.RequestMonitor; import org.eclipse.dd.dsf.datamodel.IDMContext; import org.eclipse.dd.dsf.debug.DsfDebugPlugin; import org.eclipse.dd.dsf.debug.service.IMemory; +import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.dsf.service.IDsfService; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IMemoryBlockRetrieval; +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.util.tracker.ServiceTracker; /** - * + * Implementation of memory access API of the Eclipse standard debug model. + *
Note: This is only a sample implementation intended as a starting point. */ -public class DsfMemoryBlockRetrieval implements IMemoryBlockRetrieval { - +public class DsfMemoryBlockRetrieval extends PlatformObject + implements IMemoryBlockRetrieval +{ + private final String fModelId; + private final DsfSession fSession; + private final DsfExecutor fExecutor; private final IDMContext fContext; private final ServiceTracker fServiceTracker; - public DsfMemoryBlockRetrieval(IDMContext dmc) { + public DsfMemoryBlockRetrieval(String modelId, IDMContext dmc) throws DebugException { + fModelId = modelId; fContext = dmc; + fSession = DsfSession.getSession(fContext.getSessionId()); + if (fSession == null) { + throw new IllegalArgumentException("Session for context " + fContext + " is not active"); //$NON-NLS-1$ //$NON-NLS-2$ + } + fExecutor = fSession.getExecutor(); String memoryServiceFilter = - "(&" + - "(OBJECTCLASS=" + IMemory.class.getName() + ")" + - "(" + IDsfService.PROP_SESSION_ID + "=" + dmc.getSessionId() + ")" + - ")"; - fServiceTracker = new ServiceTracker(DsfDebugPlugin.getBundleContext(), memoryServiceFilter, null); + "(&" + //$NON-NLS-1$ + "(OBJECTCLASS=" + IMemory.class.getName() + ")" + //$NON-NLS-1$//$NON-NLS-2$ + "(" + IDsfService.PROP_SESSION_ID + "=" + dmc.getSessionId() + ")" + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + ")"; //$NON-NLS-1$ + BundleContext bundle = DsfDebugPlugin.getBundleContext(); + try { + fServiceTracker = new ServiceTracker(bundle, bundle.createFilter(memoryServiceFilter), null); + } catch (InvalidSyntaxException e) { + throw new DebugException(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Error creating service filter.", e)); //$NON-NLS-1$ + } fServiceTracker.open(); } - public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException { + public IMemoryBlock getMemoryBlock(final long startAddress, final long length) throws DebugException { + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + IMemory memoryService = (IMemory)fServiceTracker.getService(); + if (memoryService != null) { + final byte[] buf = new byte[(int)length]; + memoryService.getMemory( + fContext, new Addr32(startAddress), 32, buf, 0, (int)length, 0, + new RequestMonitor(fExecutor, rm) { + @Override + protected void handleOK() { + rm.setData(new DsfMemoryBlock(DsfMemoryBlockRetrieval.this, fModelId, startAddress, buf)); + rm.done(); + } + }); + } + + } + }; + fExecutor.execute(query); + try { + return query.get(); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } return null; } public boolean supportsStorageRetrieval() { - return false; + return true; } - }