Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2013-08-12 17:39:39 +0000
committerMike Rennie2013-08-12 17:40:15 +0000
commit7076decdceeadf55f1dc9aa6a3bb65ecf5b64f83 (patch)
tree84b0fe33f090bb92f48dd05f91ecddca48f29bce /org.eclipse.debug.examples.memory/src/org
parent67cbbcd605b80ae26e36621af6643bf983f3de76 (diff)
downloadeclipse.platform.debug-7076decdceeadf55f1dc9aa6a3bb65ecf5b64f83.tar.gz
eclipse.platform.debug-7076decdceeadf55f1dc9aa6a3bb65ecf5b64f83.tar.xz
eclipse.platform.debug-7076decdceeadf55f1dc9aa6a3bb65ecf5b64f83.zip
Bug 414212 - Add memory examples
Diffstat (limited to 'org.eclipse.debug.examples.memory/src/org')
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/MemoryViewSamplePlugin.java127
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/Messages.java20
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleDebugTarget.java323
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleMemoryBlock.java422
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegister.java31
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegisterGroup.java70
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleStackFrame.java186
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleThread.java273
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleValue.java59
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleVariable.java80
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/messages.properties6
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleEngine.java367
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleMemoryUnit.java36
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchConfigurationDelegateEx.java42
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchTabGroup.java36
-rw-r--r--org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleModelPresentation.java168
16 files changed, 2246 insertions, 0 deletions
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/MemoryViewSamplePlugin.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/MemoryViewSamplePlugin.java
new file mode 100644
index 000000000..eec34d170
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/MemoryViewSamplePlugin.java
@@ -0,0 +1,127 @@
+package org.eclipse.debug.examples.internal.memory;
+
+import java.net.URL;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class for sample adapter
+ */
+public class MemoryViewSamplePlugin extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.debug.examples.memory"; //$NON-NLS-1$
+
+ // The shared instance.
+ private static MemoryViewSamplePlugin plugin;
+
+ // Resource bundle.
+ private ResourceBundle resourceBundle;
+
+ private final static String ICONS_PATH = "icons/full/";//$NON-NLS-1$
+ private final static String PATH_OBJECT = ICONS_PATH + "obj16/"; //Model object icons //$NON-NLS-1$
+
+ public final static String IMG_OBJ_HEX_TREE = "IMB_OBJ_HEX_TREE"; //$NON-NLS-1$
+ public final static String IMG_OBJ_MEMORY_SEGMENT = "IMG_OBJ_MEMORY_SEGMENT"; //$NON-NLS-1$
+ public final static String IMG_OBJ_MEMORY_UNIT = "IMG_OBJ_MEMORY_UNIT"; //$NON-NLS-1$
+
+ /**
+ * The constructor.
+ */
+ public MemoryViewSamplePlugin() {
+ super();
+ plugin = this;
+ try {
+ resourceBundle = ResourceBundle.getBundle(PLUGIN_ID);
+ } catch (MissingResourceException x) {
+ resourceBundle = null;
+ }
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static MemoryViewSamplePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle, or 'key' if not
+ * found.
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle = MemoryViewSamplePlugin.getDefault().getResourceBundle();
+ try {
+ return (bundle != null) ? bundle.getString(key) : key;
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle() {
+ return resourceBundle;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse
+ * .jface.resource.ImageRegistry)
+ */
+ @Override
+ protected void initializeImageRegistry(ImageRegistry reg) {
+ declareImage(IMG_OBJ_HEX_TREE, PATH_OBJECT + "hex_tree.gif"); //$NON-NLS-1$
+ declareImage(IMG_OBJ_MEMORY_SEGMENT, PATH_OBJECT + "memory_segment.gif"); //$NON-NLS-1$
+ declareImage(IMG_OBJ_MEMORY_UNIT, PATH_OBJECT + "memory_unit.gif"); //$NON-NLS-1$
+ }
+
+ /**
+ * Declares a workbench image given the path of the image file (relative to
+ * the workbench plug-in). This is a helper method that creates the image
+ * descriptor and passes it to the main <code>declareImage</code> method.
+ *
+ * @param symbolicName the symbolic name of the image
+ * @param path the path of the image file relative to the base of the
+ * workbench plug-ins install directory <code>false</code> if
+ * this is not a shared image
+ */
+ private void declareImage(String key, String path) {
+ ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
+ Bundle bundle = Platform.getBundle(PLUGIN_ID);
+ URL url = null;
+ if (bundle != null) {
+ url = FileLocator.find(bundle, new Path(path), null);
+ if (url != null) {
+ desc = ImageDescriptor.createFromURL(url);
+ }
+ }
+ getImageRegistry().put(key, desc);
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/Messages.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/Messages.java
new file mode 100644
index 000000000..fda8edf73
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/Messages.java
@@ -0,0 +1,20 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.debug.examples.internal.memory.core.messages"; //$NON-NLS-1$
+ public static String SampleDebugTarget_0;
+ public static String SampleDebugTarget_1;
+ public static String SampleMemoryBlock_0;
+ public static String SampleRegisterGroup_0;
+ public static String SampleStackFrame_0;
+ public static String SampleThread_0;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleDebugTarget.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleDebugTarget.java
new file mode 100644
index 000000000..2578937a0
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleDebugTarget.java
@@ -0,0 +1,323 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.debug.examples.internal.memory.MemoryViewSamplePlugin;
+import org.eclipse.debug.examples.internal.memory.engine.SampleEngine;
+
+/**
+ * Abstract Sample debug target
+ */
+
+public class SampleDebugTarget extends DebugElement implements IDebugTarget, IMemoryBlockRetrievalExtension {
+
+ boolean fTerminate = false;
+ boolean fSuspend = true;
+
+ protected ILaunch fLaunch;
+ protected SampleEngine fEngine = new SampleEngine();
+ protected ArrayList<IMemoryBlockExtension> fMemoryBlocks = new ArrayList<IMemoryBlockExtension>();
+ protected IThread fThread;
+ protected boolean fBusy;
+
+ /**
+ * Creates SampleDebugTarget
+ *
+ * @param launch the launch this debug target belongs to
+ */
+ public SampleDebugTarget(ILaunch launch) {
+ super(null);
+ fLaunch = launch;
+ fireEvent(new DebugEvent(this, DebugEvent.CREATE));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugTarget#getProcess()
+ */
+ @Override
+ public IProcess getProcess() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads()
+ */
+ @Override
+ public boolean hasThreads() throws DebugException {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IDebugTarget#supportsBreakpoint(org.eclipse
+ * .debug.core.model.IBreakpoint)
+ */
+ @Override
+ public boolean supportsBreakpoint(IBreakpoint breakpoint) {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
+ */
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
+ */
+ @Override
+ public ILaunch getLaunch() {
+ return fLaunch;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
+ */
+ @Override
+ public boolean canTerminate() {
+ return !fTerminate;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
+ */
+ @Override
+ public boolean isTerminated() {
+ return fTerminate;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#terminate()
+ */
+ @Override
+ public void terminate() throws DebugException {
+ fTerminate = true;
+ fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
+ */
+ @Override
+ public boolean canResume() {
+ return fSuspend && !fTerminate;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
+ */
+ @Override
+ public boolean canSuspend() {
+ return !fSuspend && !fTerminate;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
+ */
+ @Override
+ public boolean isSuspended() {
+ return fSuspend;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#resume()
+ */
+ @Override
+ public void resume() throws DebugException {
+ fSuspend = false;
+ fEngine.resume();
+ fireEvent(new DebugEvent(this, DebugEvent.RESUME));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
+ */
+ @Override
+ public void suspend() throws DebugException {
+ fSuspend = true;
+ fireEvent(new DebugEvent(getEngine().getThreads(this)[0], DebugEvent.SUSPEND));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse
+ * .debug.core.model.IBreakpoint)
+ */
+ @Override
+ public void breakpointAdded(IBreakpoint breakpoint) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse
+ * .debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
+ */
+ @Override
+ public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse
+ * .debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
+ */
+ @Override
+ public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDisconnect#canDisconnect()
+ */
+ @Override
+ public boolean canDisconnect() {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDisconnect#disconnect()
+ */
+ @Override
+ public void disconnect() throws DebugException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected()
+ */
+ @Override
+ public boolean isDisconnected() {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval
+ * ()
+ */
+ @Override
+ public boolean supportsStorageRetrieval() {
+ return true;
+ }
+
+ /**
+ * @return the debug engine
+ */
+ public SampleEngine getEngine() {
+ return fEngine;
+ }
+
+ /**
+ * Remove the memory block from this debug session.
+ *
+ * @param memBlk
+ */
+ public void removeMemoryBlock(IMemoryBlock memBlk) {
+ fMemoryBlocks.remove(memBlk);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long,
+ * long)
+ */
+ @Override
+ public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException {
+
+ return null;
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+
+ if (adapter == ILaunch.class) {
+ return getLaunch();
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public IThread[] getThreads() throws DebugException {
+ if (isTerminated()) {
+ return new IThread[0];
+ }
+
+ return getEngine().getThreads(this);
+ }
+
+ @Override
+ public String getName() throws DebugException {
+ return Messages.SampleDebugTarget_0;
+ }
+
+ @Override
+ public String getModelIdentifier() {
+ return MemoryViewSamplePlugin.PLUGIN_ID;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension#
+ * getExtendedMemoryBlock(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public IMemoryBlockExtension getExtendedMemoryBlock(String expression, Object context) throws DebugException {
+
+ // ask debug engine for an address
+ BigInteger address = getEngine().evaluateExpression(expression, context);
+
+ // if address can be evaluated to an address, create memory block
+ if (address != null) {
+ IMemoryBlockExtension memoryBlock = new SampleMemoryBlock(this, expression, address);
+ fMemoryBlocks.add(memoryBlock);
+
+ return memoryBlock;
+ }
+ // otherwise throw debug exception
+ IStatus status = new Status(IStatus.ERROR, MemoryViewSamplePlugin.PLUGIN_ID, 0, Messages.SampleDebugTarget_1, null);
+ DebugException exception = new DebugException(status);
+ throw exception;
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleMemoryBlock.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleMemoryBlock.java
new file mode 100644
index 000000000..23990ea05
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleMemoryBlock.java
@@ -0,0 +1,422 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
+import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.debug.examples.internal.memory.MemoryViewSamplePlugin;
+import org.eclipse.debug.examples.internal.memory.launchconfig.SampleModelPresentation;
+import org.eclipse.jface.viewers.IColorProvider;
+
+/**
+ * Memory Block Implementation
+ *
+ */
+public class SampleMemoryBlock extends DebugElement implements IMemoryBlockExtension {
+
+ private String fExpression;
+ private SampleDebugTarget fDebugTarget;
+
+ private boolean isEnabled = true;
+ private BigInteger fBaseAddress;
+
+ private ArrayList<Object> fConnections = new ArrayList<Object>();
+
+ /**
+ * Creates memory block
+ *
+ * @param debugTarget
+ * @param expression
+ * @param address
+ */
+ public SampleMemoryBlock(SampleDebugTarget debugTarget, String expression, BigInteger address) {
+ super(debugTarget);
+ fDebugTarget = debugTarget;
+ fExpression = expression;
+ fBaseAddress = address;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getBigBaseAddress()
+ */
+ @Override
+ public BigInteger getBigBaseAddress() throws DebugException {
+ fBaseAddress = fDebugTarget.getEngine().evaluateExpression(fExpression, null);
+ return fBaseAddress;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#
+ * supportBaseAddressModification()
+ */
+ @Override
+ public boolean supportBaseAddressModification() throws DebugException {
+ return fDebugTarget.getEngine().suppostsBaseAddressModification(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#setBaseAddress(java
+ * .math.BigInteger)
+ */
+ @Override
+ public void setBaseAddress(BigInteger address) throws DebugException {
+ try {
+ fDebugTarget.getEngine().setBaseAddress(this, address);
+ } catch (CoreException e) {
+ throw new DebugException(e.getStatus());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getBytesFromOffset
+ * (long, long)
+ */
+ @Override
+ synchronized public MemoryByte[] getBytesFromOffset(BigInteger offset, long length) throws DebugException {
+ BigInteger address = fBaseAddress.subtract(offset);
+ return getBytesFromAddress(address, length);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getBytesFromAddress
+ * (java.math.BigInteger, long)
+ */
+ @Override
+ public MemoryByte[] getBytesFromAddress(BigInteger address, long length) throws DebugException {
+
+ try {
+ MemoryByte[] bytes = new MemoryByte[(int) length * fDebugTarget.getEngine().getAddressableSize()];
+ BigInteger addressCnt = address;
+ int lengthCnt = (int) length;
+ int i = 0;
+
+ // asks engine to get bytes from address
+ MemoryByte[] engineBytes = fDebugTarget.getEngine().getBytesFromAddress(addressCnt, lengthCnt);
+ System.arraycopy(engineBytes, 0, bytes, i, engineBytes.length);
+
+ // if engine did not return enough memory, pad with dummy memory
+ for (int j = i + engineBytes.length; j < bytes.length; j++) {
+ MemoryByte mb = new MemoryByte((byte) 0);
+ mb.setReadable(false);
+ mb.setWritable(false);
+ mb.setBigEndian(fDebugTarget.getEngine().isBigEndian(address.add(BigInteger.valueOf(j))));
+ bytes[j] = mb;
+ }
+
+ return bytes;
+ } catch (RuntimeException e) {
+ throw e;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#connect(java.lang.
+ * Object)
+ */
+ @Override
+ public void connect(Object object) {
+
+ if (!fConnections.contains(object)) {
+ fConnections.add(object);
+ }
+
+ if (fConnections.size() == 1) {
+ enable();
+ }
+ }
+
+ /**
+ * Enable this memory block
+ */
+ private void enable() {
+ isEnabled = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#disconnect(java.lang
+ * .Object)
+ */
+ @Override
+ public void disconnect(Object object) {
+
+ if (fConnections.contains(object)) {
+ fConnections.remove(object);
+ }
+
+ if (fConnections.size() == 0) {
+ disable();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getConnected()
+ */
+ @Override
+ public Object[] getConnections() {
+ return fConnections.toArray();
+ }
+
+ /**
+ * Disable this memory block
+ */
+ private void disable() {
+ isEnabled = false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlock#getStartAddress()
+ */
+ @Override
+ public long getStartAddress() {
+ // no need to implement this method as it belongs to IMemoryBlock
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlock#getLength()
+ */
+ @Override
+ public long getLength() {
+ // no need to implement this method as it belongs to IMemoryBlock
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlock#getBytes()
+ */
+ @Override
+ public byte[] getBytes() throws DebugException {
+ // no need to implement this method as it belongs to IMemoryBlock
+ return new byte[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlock#supportsValueModification()
+ */
+ @Override
+ public boolean supportsValueModification() {
+ return fDebugTarget.getEngine().supportsValueModification(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlock#setValue(long, byte[])
+ */
+ @Override
+ public void setValue(BigInteger offset, byte[] bytes) throws DebugException {
+ try {
+ // ask the engine to modify memory at specified address
+ fDebugTarget.getEngine().setValue(fBaseAddress.add(offset), bytes);
+ fireContentChangeEvent();
+ } catch (RuntimeException e) {
+ IStatus status = new Status(IStatus.ERROR, MemoryViewSamplePlugin.PLUGIN_ID, 0, Messages.SampleMemoryBlock_0, e);
+ DebugException exception = new DebugException(status);
+ throw exception;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
+ */
+ @Override
+ public String getModelIdentifier() {
+ return getDebugTarget().getModelIdentifier();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
+ */
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fDebugTarget;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
+ */
+ @Override
+ public ILaunch getLaunch() {
+ return fDebugTarget.getLaunch();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Class adapter) {
+
+ if (adapter.equals(IMemoryBlockRetrievalExtension.class)) {
+ return getDebugTarget();
+ }
+
+ if (adapter == IColorProvider.class) {
+ return SampleModelPresentation.getSampleModelPresentation();
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getExpression()
+ */
+ @Override
+ public String getExpression() {
+ return fExpression;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#dispose()
+ */
+ @Override
+ public void dispose() throws DebugException {
+ // remove this memory block from debug target
+ fDebugTarget.removeMemoryBlock(this);
+ }
+
+ /**
+ * @return is enabled
+ */
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.ibm.debug.extended.ui.IMemoryBlockExtension#getMemoryBlockRetrieval()
+ */
+ @Override
+ public IMemoryBlockRetrieval getMemoryBlockRetrieval() {
+ return getDebugTarget();
+ }
+
+ /**
+ *
+ */
+ private void fireContentChangeEvent() {
+ DebugEvent evt = new DebugEvent(this, DebugEvent.CHANGE);
+ fireEvent(evt);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.ibm.debug.extended.ui.IMemoryBlockExtension#isMemoryChangesManaged()
+ */
+ @Override
+ public boolean supportsChangeManagement() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getAddressableSize()
+ */
+ @Override
+ public int getAddressableSize() throws DebugException {
+ return fDebugTarget.getEngine().getAddressableSize();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getAddressSize()
+ */
+ @Override
+ public int getAddressSize() throws DebugException {
+ try {
+ return fDebugTarget.getEngine().getAddressSize();
+ } catch (CoreException e) {
+ throw new DebugException(e.getStatus());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getMemoryBlockStartAddress
+ * ()
+ */
+ @Override
+ public BigInteger getMemoryBlockStartAddress() throws DebugException {
+
+ // if (true)
+ // return fBaseAddress.subtract(BigInteger.valueOf(250));
+ // Return null by default.
+ // Null is acceptable if default start address is to be used.
+ // Default is 0.
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.IMemoryBlockExtension#getMemoryBlockEndAddress
+ * ()
+ */
+ @Override
+ public BigInteger getMemoryBlockEndAddress() throws DebugException {
+
+ // if (true)
+ // return fBaseAddress.add(BigInteger.valueOf(250));
+ // Return null by default.
+ // Null is accpetable if default end address is to be used.
+ // Default end address is calculated based on address size.
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlock#setValue(long, byte[])
+ */
+ @Override
+ public void setValue(long offset, byte[] bytes) throws DebugException {
+ // do not need to implement for IMemoryBlockExtension
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getBigLength()
+ */
+ @Override
+ public BigInteger getBigLength() throws DebugException {
+ // return -1 by default and default length is calculated
+ return BigInteger.valueOf(-1);
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegister.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegister.java
new file mode 100644
index 000000000..9d8a535b8
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegister.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IRegister;
+import org.eclipse.debug.core.model.IRegisterGroup;
+
+public class SampleRegister extends SampleVariable implements IRegister {
+
+ private SampleRegisterGroup fGroup;
+
+ SampleRegister(SampleStackFrame frame, SampleRegisterGroup group, String name) {
+ super(frame, name);
+ fGroup = group;
+ }
+
+ @Override
+ public IRegisterGroup getRegisterGroup() throws DebugException {
+ return fGroup;
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegisterGroup.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegisterGroup.java
new file mode 100644
index 000000000..a15421f89
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleRegisterGroup.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IRegister;
+import org.eclipse.debug.core.model.IRegisterGroup;
+
+public class SampleRegisterGroup extends DebugElement implements IRegisterGroup {
+
+ SampleRegister fRegister1;
+ SampleRegister fRegister2;
+ SampleStackFrame fFrame;
+
+ public SampleRegisterGroup(SampleStackFrame frame) {
+ super(frame.getDebugTarget());
+ fFrame = frame;
+ }
+
+ @Override
+ public String getName() throws DebugException {
+ return Messages.SampleRegisterGroup_0;
+ }
+
+ @Override
+ public IRegister[] getRegisters() throws DebugException {
+ if (fRegister1 == null) {
+ fRegister1 = new SampleRegister(fFrame, this, "eax"); //$NON-NLS-1$
+ }
+
+ if (fRegister2 == null) {
+ fRegister2 = new SampleRegister(fFrame, this, "ebx"); //$NON-NLS-1$
+ }
+
+ return new IRegister[] { fRegister1, fRegister2 };
+ }
+
+ @Override
+ public boolean hasRegisters() throws DebugException {
+ return true;
+ }
+
+ @Override
+ public String getModelIdentifier() {
+ return fFrame.getModelIdentifier();
+ }
+
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fFrame.getDebugTarget();
+ }
+
+ @Override
+ public ILaunch getLaunch() {
+ return fFrame.getLaunch();
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleStackFrame.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleStackFrame.java
new file mode 100644
index 000000000..687e6e4e1
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleStackFrame.java
@@ -0,0 +1,186 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IRegisterGroup;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ *
+ */
+public class SampleStackFrame extends DebugElement implements IStackFrame {
+
+ private SampleThread fThread;
+ private SampleRegisterGroup fRegisterGroup;
+ private long timeStamp;
+ private String fName;
+
+ /**
+ * Constructs a SampleStackFrame
+ *
+ * @param thread
+ * @param name
+ */
+ public SampleStackFrame(SampleThread thread, String name) {
+ super(thread.getDebugTarget());
+ fThread = thread;
+ fName = name;
+ timeStamp = System.currentTimeMillis();
+ }
+
+ @Override
+ public IThread getThread() {
+ return fThread;
+ }
+
+ @Override
+ public IVariable[] getVariables() throws DebugException {
+
+ return new IVariable[] { new SampleVariable(this, "sampleVariable") }; //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean hasVariables() throws DebugException {
+ return true;
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter == ILaunch.class) {
+ return getLaunch();
+ }
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public int getLineNumber() throws DebugException {
+ return 0;
+ }
+
+ @Override
+ public int getCharStart() throws DebugException {
+ return 0;
+ }
+
+ @Override
+ public int getCharEnd() throws DebugException {
+ return 0;
+ }
+
+ @Override
+ public String getName() throws DebugException {
+ return NLS.bind(Messages.SampleStackFrame_0, new Object[] {
+ fName, timeStamp });
+ }
+
+ @Override
+ public IRegisterGroup[] getRegisterGroups() throws DebugException {
+ if (fRegisterGroup == null) {
+ fRegisterGroup = new SampleRegisterGroup(this);
+ }
+ return new IRegisterGroup[] { fRegisterGroup };
+ }
+
+ @Override
+ public boolean hasRegisterGroups() throws DebugException {
+ return true;
+ }
+
+ @Override
+ public String getModelIdentifier() {
+ return fThread.getModelIdentifier();
+ }
+
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fThread.getDebugTarget();
+ }
+
+ @Override
+ public ILaunch getLaunch() {
+ return fThread.getDebugTarget().getLaunch();
+ }
+
+ @Override
+ public boolean canStepInto() {
+ return false;
+ }
+
+ @Override
+ public boolean canStepOver() {
+ return fThread.canStepOver();
+ }
+
+ @Override
+ public boolean canStepReturn() {
+ return false;
+ }
+
+ @Override
+ public boolean isStepping() {
+ return false;
+ }
+
+ @Override
+ public void stepInto() throws DebugException {
+
+ }
+
+ @Override
+ public void stepOver() throws DebugException {
+ fThread.stepOver();
+ }
+
+ @Override
+ public void stepReturn() throws DebugException {
+
+ }
+
+ @Override
+ public boolean canResume() {
+ return fThread.canResume();
+ }
+
+ @Override
+ public boolean canSuspend() {
+ return fThread.canSuspend();
+ }
+
+ @Override
+ public boolean isSuspended() {
+ return fThread.isSuspended();
+ }
+
+ @Override
+ public void resume() throws DebugException {
+ fThread.resume();
+
+ }
+
+ @Override
+ public void suspend() throws DebugException {
+ fThread.suspend();
+ }
+
+ @Override
+ public boolean canTerminate() {
+ return fThread.canTerminate();
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return fThread.isTerminated();
+ }
+
+ @Override
+ public void terminate() throws DebugException {
+ fThread.terminate();
+
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleThread.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleThread.java
new file mode 100644
index 000000000..a198f4f30
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleThread.java
@@ -0,0 +1,273 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+
+/**
+ * Abstract Sample Thread
+ *
+ */
+public class SampleThread extends DebugElement implements IThread {
+
+ private SampleDebugTarget fTarget;
+
+ /**
+ * Constructs SampleThread
+ *
+ * @param target
+ */
+ public SampleThread(SampleDebugTarget target) {
+ super(target);
+ fTarget = target;
+ try {
+ getStackFrames();
+ } catch (DebugException e) {
+ e.printStackTrace();
+ }
+ fireEvent(new DebugEvent(this, DebugEvent.SUSPEND));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#getStackFrames()
+ */
+ @Override
+ public IStackFrame[] getStackFrames() throws DebugException {
+ return ((SampleDebugTarget) getDebugTarget()).getEngine().getStackframes(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
+ */
+ @Override
+ public boolean hasStackFrames() throws DebugException {
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#getPriority()
+ */
+ @Override
+ public int getPriority() throws DebugException {
+
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
+ */
+ @Override
+ public IStackFrame getTopStackFrame() throws DebugException {
+ return ((SampleDebugTarget) getDebugTarget()).getEngine().getStackframes(this)[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#getName()
+ */
+ @Override
+ public String getName() throws DebugException {
+ return Messages.SampleThread_0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
+ */
+ @Override
+ public IBreakpoint[] getBreakpoints() {
+
+ return new IBreakpoint[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
+ */
+ @Override
+ public String getModelIdentifier() {
+ return fTarget.getModelIdentifier();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
+ */
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fTarget;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
+ */
+ @Override
+ public ILaunch getLaunch() {
+ return fTarget.getLaunch();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
+ */
+ @Override
+ public boolean canResume() {
+ return fTarget.canResume();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
+ */
+ @Override
+ public boolean canSuspend() {
+ return fTarget.canSuspend();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
+ */
+ @Override
+ public boolean isSuspended() {
+ return fTarget.isSuspended();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#resume()
+ */
+ @Override
+ public void resume() throws DebugException {
+ fTarget.resume();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
+ */
+ @Override
+ public void suspend() throws DebugException {
+ fTarget.suspend();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#canStepInto()
+ */
+ @Override
+ public boolean canStepInto() {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#canStepOver()
+ */
+ @Override
+ public boolean canStepOver() {
+ if (!fTarget.isTerminated()) {
+ return true;
+ }
+
+ return fTarget.isSuspended();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#canStepReturn()
+ */
+ @Override
+ public boolean canStepReturn() {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#isStepping()
+ */
+ @Override
+ public boolean isStepping() {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#stepInto()
+ */
+ @Override
+ public void stepInto() throws DebugException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#stepOver()
+ */
+ @Override
+ public void stepOver() throws DebugException {
+ fTarget.resume();
+ fTarget.suspend();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IStep#stepReturn()
+ */
+ @Override
+ public void stepReturn() throws DebugException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
+ */
+ @Override
+ public boolean canTerminate() {
+ return fTarget.canTerminate();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
+ */
+ @Override
+ public boolean isTerminated() {
+ return fTarget.isTerminated();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ITerminate#terminate()
+ */
+ @Override
+ public void terminate() throws DebugException {
+ fTarget.terminate();
+
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter == ILaunch.class) {
+ return getLaunch();
+ }
+ return super.getAdapter(adapter);
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleValue.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleValue.java
new file mode 100644
index 000000000..07a067dfe
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleValue.java
@@ -0,0 +1,59 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+
+public class SampleValue extends DebugElement implements IValue {
+
+ private SampleVariable fVariable;
+
+ public SampleValue(SampleVariable variable) {
+ super(variable.getDebugTarget());
+ fVariable = variable;
+ }
+
+ @Override
+ public String getReferenceTypeName() throws DebugException {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public String getValueString() throws DebugException {
+ return String.valueOf(System.currentTimeMillis());
+ }
+
+ @Override
+ public boolean isAllocated() throws DebugException {
+ return false;
+ }
+
+ @Override
+ public IVariable[] getVariables() throws DebugException {
+ return new IVariable[0];
+ }
+
+ @Override
+ public boolean hasVariables() throws DebugException {
+ return false;
+ }
+
+ @Override
+ public String getModelIdentifier() {
+ return fVariable.getModelIdentifier();
+ }
+
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fVariable.getDebugTarget();
+ }
+
+ @Override
+ public ILaunch getLaunch() {
+ return fVariable.getLaunch();
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleVariable.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleVariable.java
new file mode 100644
index 000000000..a849248d1
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/SampleVariable.java
@@ -0,0 +1,80 @@
+package org.eclipse.debug.examples.internal.memory.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.DebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+
+public class SampleVariable extends DebugElement implements IVariable {
+
+ private final SampleStackFrame fFrame;
+ private String fName;
+
+ SampleVariable(SampleStackFrame frame, String name) {
+ super(frame.getDebugTarget());
+ fFrame = frame;
+ fName = name;
+ }
+
+ @Override
+ public IValue getValue() throws DebugException {
+ return new SampleValue(this);
+ }
+
+ @Override
+ public String getName() throws DebugException {
+ return fName;
+ }
+
+ @Override
+ public String getReferenceTypeName() throws DebugException {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean hasValueChanged() throws DebugException {
+ return false;
+ }
+
+ @Override
+ public String getModelIdentifier() {
+ return fFrame.getModelIdentifier();
+ }
+
+ @Override
+ public IDebugTarget getDebugTarget() {
+ return fFrame.getDebugTarget();
+ }
+
+ @Override
+ public ILaunch getLaunch() {
+ return fFrame.getLaunch();
+ }
+
+ @Override
+ public void setValue(IValue value) throws DebugException {
+
+ }
+
+ @Override
+ public boolean supportsValueModification() {
+ return false;
+ }
+
+ @Override
+ public boolean verifyValue(IValue value) throws DebugException {
+ return false;
+ }
+
+ @Override
+ public void setValue(String expression) throws DebugException {
+
+ }
+
+ @Override
+ public boolean verifyValue(String expression) throws DebugException {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/messages.properties b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/messages.properties
new file mode 100644
index 000000000..f3363cbf1
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/core/messages.properties
@@ -0,0 +1,6 @@
+SampleDebugTarget_0=[Debug Target:] Memory View Example Program
+SampleDebugTarget_1=Expression cannot be evaluated to an address
+SampleMemoryBlock_0=Failed to edit.
+SampleRegisterGroup_0=Register Group
+SampleStackFrame_0=[Stackframe:] {0} {1}
+SampleThread_0=[Thread:] Thread \#1
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleEngine.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleEngine.java
new file mode 100644
index 000000000..c82fc8a66
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleEngine.java
@@ -0,0 +1,367 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.debug.examples.internal.memory.engine;
+
+import java.math.BigInteger;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Random;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.debug.examples.internal.memory.core.SampleDebugTarget;
+import org.eclipse.debug.examples.internal.memory.core.SampleMemoryBlock;
+import org.eclipse.debug.examples.internal.memory.core.SampleStackFrame;
+import org.eclipse.debug.examples.internal.memory.core.SampleThread;
+
+/**
+ * Sample engine for sample deug adapter This engine randomly generates content
+ * for a memory block. To get to this engine, call
+ * {@link SampleDebugTarget#getEngine()};
+ */
+public class SampleEngine {
+
+ Random fRandom = new Random();
+ byte[] fMemory;
+ Hashtable<BigInteger, SampleMemoryUnit> memoryBlockTable;
+ Hashtable<String, BigInteger> expressionAddressTable = new Hashtable<String, BigInteger>();
+ Hashtable<SampleDebugTarget, Object> threadTable = new Hashtable<SampleDebugTarget, Object>();
+ Hashtable<SampleThread, Object> stackframeTable = new Hashtable<SampleThread, Object>();
+
+ Random random = new Random();
+
+ /**
+ * Allow debug adapters to get memory from an address
+ *
+ * @param address
+ * @param length
+ * @return memory byte from an address
+ * @throws RuntimeException
+ */
+ synchronized public MemoryByte[] getBytesFromAddress(BigInteger address, long length) throws RuntimeException {
+
+ if (memoryBlockTable == null) {
+ // create new memoryBlock table
+ memoryBlockTable = new Hashtable<BigInteger, SampleMemoryUnit>();
+ byte[] bytes = new byte[(int) length * getAddressableSize()];
+ BigInteger addressKey = address;
+
+ random.nextBytes(bytes);
+
+ for (int i = 0; i < bytes.length; i = i + getAddressableSize()) {
+ addressKey = addressKey.add(BigInteger.valueOf(1));
+
+ MemoryByte[] byteUnit = new MemoryByte[getAddressableSize()];
+ for (int j = 0; j < getAddressableSize(); j++) {
+ MemoryByte oneByte = new MemoryByte(bytes[i + j]);
+ oneByte.setBigEndian(isBigEndian(addressKey));
+ oneByte.setWritable(isWritable(addressKey));
+ oneByte.setReadable(isReadable(addressKey));
+ byteUnit[j] = oneByte;
+ }
+ SampleMemoryUnit unit = new SampleMemoryUnit(byteUnit);
+ memoryBlockTable.put(addressKey, unit);
+ }
+ }
+
+ MemoryByte[] returnBytes = new MemoryByte[(int) length * getAddressableSize()];
+ BigInteger addressKey;
+
+ for (int i = 0; i < returnBytes.length; i = i + getAddressableSize()) {
+ addressKey = address.add(BigInteger.valueOf(i / getAddressableSize()));
+ SampleMemoryUnit temp = (memoryBlockTable.get(addressKey));
+
+ // if memoryBlock does not already exist in the table, generate a
+ // value
+ if (temp == null) {
+ byte[] x = new byte[getAddressableSize()];
+ random.nextBytes(x);
+ byte flag = 0;
+ flag |= MemoryByte.READABLE;
+ flag |= MemoryByte.ENDIANESS_KNOWN;
+ flag |= MemoryByte.WRITABLE;
+
+ MemoryByte[] byteUnit = new MemoryByte[getAddressableSize()];
+ for (int j = 0; j < getAddressableSize(); j++) {
+ MemoryByte oneByte = new MemoryByte(x[j], flag);
+ byteUnit[j] = oneByte;
+ byteUnit[j].setBigEndian(isBigEndian(addressKey));
+ byteUnit[j].setWritable(isWritable(addressKey));
+ byteUnit[j].setReadable(isReadable(addressKey));
+ returnBytes[i + j] = oneByte;
+ }
+ SampleMemoryUnit unit = new SampleMemoryUnit(byteUnit);
+ memoryBlockTable.put(addressKey, unit);
+
+ } else {
+ MemoryByte[] bytes = temp.getBytes();
+
+ for (int j = 0; j < bytes.length; j++) {
+ MemoryByte oneByte = new MemoryByte(bytes[j].getValue(), bytes[j].getFlags());
+ returnBytes[i + j] = oneByte;
+ returnBytes[i + j].setBigEndian(isBigEndian(addressKey));
+ returnBytes[i + j].setWritable(isWritable(addressKey));
+ }
+ }
+ }
+
+ return returnBytes;
+ }
+
+ /**
+ * Run the debuggee
+ */
+ public void resume() {
+ changeValue();
+ }
+
+ /**
+ * Convenience function to cause changes in a memoryBlock block. Changes
+ * could result from running the program, changing a variable, etc.
+ */
+ synchronized public void changeValue() {
+ if (memoryBlockTable == null) {
+ return;
+ }
+
+ Enumeration<BigInteger> enumeration = memoryBlockTable.keys();
+ long randomChange = random.nextInt(37);
+
+ while (randomChange <= 5) {
+ randomChange = random.nextInt(37);
+ }
+
+ while (enumeration.hasMoreElements()) {
+ BigInteger key = enumeration.nextElement();
+ if (key.remainder(BigInteger.valueOf(randomChange)).equals(BigInteger.valueOf(0))) {
+ byte[] x = new byte[getAddressableSize()];
+ random.nextBytes(x);
+
+ MemoryByte unitBytes[] = new MemoryByte[getAddressableSize()];
+ for (int i = 0; i < x.length; i++) {
+ MemoryByte oneByte = new MemoryByte();
+ oneByte.setValue(x[i]);
+ oneByte.setReadable(true);
+ oneByte.setChanged(true);
+ oneByte.setHistoryKnown(true);
+ oneByte.setBigEndian(isBigEndian(key));
+ oneByte.setWritable(isWritable(key));
+ oneByte.setReadable(isReadable(key));
+ unitBytes[i] = oneByte;
+ }
+
+ SampleMemoryUnit unit = new SampleMemoryUnit(unitBytes);
+
+ memoryBlockTable.put(key, unit);
+ } else {
+ SampleMemoryUnit unit = memoryBlockTable.get(key);
+
+ MemoryByte[] bytes = unit.getBytes();
+
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i].setChanged(false);
+ bytes[i].setHistoryKnown(true);
+ }
+
+ unit.setBytes(bytes);
+
+ memoryBlockTable.put(key, unit);
+ }
+ }
+ }
+
+ /**
+ * Simulates evaluation of an expression. Given an expression, return ad
+ * address
+ *
+ * @param expression
+ * @param evalContext
+ * @return the address the expression is evaluated to
+ */
+ public BigInteger evaluateExpression(String expression, Object evalContext) {
+ BigInteger expAddress = expressionAddressTable.get(expression);
+ if (expAddress == null) {
+ int address = random.nextInt();
+
+ // make sure number is positive
+ if (address < 0) {
+ address = address * -1;
+ }
+
+ expAddress = BigInteger.valueOf(address);
+ expressionAddressTable.put(expression, expAddress);
+ }
+ return expAddress;
+ }
+
+ /**
+ * Simulates checking if storage retrieval is supported
+ *
+ * @return if the engine supports storage retrieval
+ */
+ public boolean supportsStorageRetrieval() {
+ return true;
+ }
+
+ /**
+ * Simulates modifying memory using BigInteger as the address
+ *
+ * @param address
+ * @param bytes
+ * @throws RuntimeException
+ */
+ public void setValue(BigInteger address, byte[] bytes) throws RuntimeException {
+ BigInteger convertedAddress = address;
+
+ for (int i = 0; i < bytes.length; i = i + getAddressableSize()) {
+ SampleMemoryUnit unit = memoryBlockTable.get(convertedAddress);
+
+ MemoryByte[] unitBytes = unit.getBytes();
+ for (int j = 0; j < unitBytes.length; j++) {
+ unitBytes[j].setValue(bytes[i + j]);
+ unitBytes[j].setChanged(true);
+ unitBytes[j].setHistoryKnown(true);
+ }
+ convertedAddress = convertedAddress.add(BigInteger.valueOf(1));
+ }
+ }
+
+ /**
+ * @return addrssablesize of the debuggee
+ */
+ public int getAddressableSize() {
+ return 1;
+ }
+
+ /**
+ * @param address
+ * @return true if the debuggee is big endian, false otherwise
+ */
+ public boolean isBigEndian(BigInteger address) {
+ // simulate mixed endianess in a memory block
+ // memory before the boundary address is little endian
+ // memory after the boundaress is big endian
+ BigInteger boundary = new BigInteger("12345678", 16); //$NON-NLS-1$
+ if (address.compareTo(boundary) > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param address
+ * @return true if the address is writable, false otherwise Read only
+ * segment: 0xab123456 to 0xab123556
+ */
+ public boolean isWritable(BigInteger address) {
+ BigInteger boundary = new BigInteger("ab123456", 16); //$NON-NLS-1$
+ BigInteger boundaryEnd = new BigInteger("ab123556", 16); //$NON-NLS-1$
+ if (address.compareTo(boundary) > 0 && address.compareTo(boundaryEnd) < 0) {
+ return false;
+ }
+
+ boundary = new BigInteger("cd123456", 16); //$NON-NLS-1$
+ boundaryEnd = new BigInteger("cd123576", 16); //$NON-NLS-1$
+ if (address.compareTo(boundary) > 0 && address.compareTo(boundaryEnd) < 0) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+ /**
+ * @param address
+ * @return
+ */
+ public boolean isReadable(BigInteger address) {
+ BigInteger boundary = new BigInteger("cd123456", 16); //$NON-NLS-1$
+ BigInteger boundaryEnd = new BigInteger("cd123576", 16); //$NON-NLS-1$
+ if (address.compareTo(boundary) > 0 && address.compareTo(boundaryEnd) < 0) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @param target
+ * @return
+ */
+ public SampleThread[] getThreads(SampleDebugTarget target) {
+ Object thread = threadTable.get(target);
+ if (thread == null) {
+ thread = new SampleThread(target);
+ threadTable.put(target, thread);
+ }
+ return new SampleThread[] { (SampleThread) thread };
+ }
+
+ /**
+ * @param thread
+ * @return
+ */
+ public SampleStackFrame[] getStackframes(SampleThread thread) {
+ Object stackframes = stackframeTable.get(thread);
+ if (stackframes == null) {
+ stackframes = createStackframes(thread);
+ stackframeTable.put(thread, stackframes);
+ }
+ return (SampleStackFrame[]) stackframes;
+ }
+
+ /**
+ *
+ */
+ private SampleStackFrame[] createStackframes(SampleThread thread) {
+ SampleStackFrame[] stackframes = new SampleStackFrame[2];
+ stackframes[0] = new SampleStackFrame(thread, "Frame1"); //$NON-NLS-1$
+ stackframes[1] = new SampleStackFrame(thread, "Frame2"); //$NON-NLS-1$
+ return stackframes;
+ }
+
+ /**
+ * @param mb
+ * @return true if memory block is to support base address modification,
+ * false otherwise
+ */
+ public boolean suppostsBaseAddressModification(SampleMemoryBlock mb) {
+ return false;
+ }
+
+ /**
+ * Sets the base address of this memory block
+ *
+ * @param mb the memory block to change base address
+ * @param address the new base address of the memory block
+ * @throws CoreException
+ */
+ public void setBaseAddress(SampleMemoryBlock mb, BigInteger address) throws CoreException {
+ }
+
+ /**
+ * @param mb
+ * @return true if this memory block supports value modification, false
+ * otherwise
+ * @throws CoreException
+ */
+ public boolean supportsValueModification(SampleMemoryBlock mb) {
+ return true;
+ }
+
+ /**
+ * @return address size of the debuggee
+ * @throws CoreException
+ */
+ public int getAddressSize() throws CoreException {
+ return 4;
+ }
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleMemoryUnit.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleMemoryUnit.java
new file mode 100644
index 000000000..bf2ebb89e
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/engine/SampleMemoryUnit.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.internal.memory.engine;
+
+import org.eclipse.debug.core.model.MemoryByte;
+
+/**
+ * For testing addressable size > 1. Group each addressable unit in a MemoryByte
+ * array.
+ *
+ */
+public class SampleMemoryUnit {
+
+ MemoryByte[] fBytes;
+
+ public SampleMemoryUnit(MemoryByte[] bytes) {
+ fBytes = bytes;
+ }
+
+ public MemoryByte[] getBytes() {
+ return fBytes;
+ }
+
+ public void setBytes(MemoryByte[] bytes) {
+ fBytes = bytes;
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchConfigurationDelegateEx.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchConfigurationDelegateEx.java
new file mode 100644
index 000000000..475792f93
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchConfigurationDelegateEx.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.internal.memory.launchconfig;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.debug.examples.internal.memory.core.SampleDebugTarget;
+
+/**
+ * Sample Launch configuraiton delegate For creating the debug target that
+ * supports IMemoryBlockExtension
+ * */
+public class SampleLaunchConfigurationDelegateEx extends LaunchConfigurationDelegate {
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.
+ * eclipse.debug.core.ILaunchConfiguration, java.lang.String,
+ * org.eclipse.debug.core.ILaunch,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ IDebugTarget target = new SampleDebugTarget(launch);
+ launch.addDebugTarget(target);
+
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchTabGroup.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchTabGroup.java
new file mode 100644
index 000000000..fc88ed59c
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleLaunchTabGroup.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.internal.memory.launchconfig;
+
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+
+/**
+ * Sample launch tab group
+ */
+public class SampleLaunchTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse
+ * .debug.ui.ILaunchConfigurationDialog, java.lang.String)
+ */
+ @Override
+ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[1];
+ tabs[0] = new CommonTab();
+ setTabs(tabs);
+ }
+
+}
diff --git a/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleModelPresentation.java b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleModelPresentation.java
new file mode 100644
index 000000000..ed87642cd
--- /dev/null
+++ b/org.eclipse.debug.examples.memory/src/org/eclipse/debug/examples/internal/memory/launchconfig/SampleModelPresentation.java
@@ -0,0 +1,168 @@
+package org.eclipse.debug.examples.internal.memory.launchconfig;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.debug.examples.internal.memory.MemoryViewSamplePlugin;
+import org.eclipse.debug.ui.IDebugModelPresentation;
+import org.eclipse.debug.ui.IValueDetailListener;
+import org.eclipse.debug.ui.memory.MemoryRenderingElement;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.progress.UIJob;
+
+/**
+ * Model presentation for sample debug adapter
+ */
+
+public class SampleModelPresentation implements IDebugModelPresentation, IColorProvider {
+
+ private static SampleModelPresentation fPresentation;
+ private static Color blue;
+
+ public static SampleModelPresentation getSampleModelPresentation() {
+ if (fPresentation == null) {
+ fPresentation = new SampleModelPresentation();
+
+ UIJob job = new UIJob("get colors") { //$NON-NLS-1$
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ Display display = MemoryViewSamplePlugin.getDefault().getWorkbench().getDisplay();
+ blue = display.getSystemColor(SWT.COLOR_BLUE);
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+ }
+
+ return fPresentation;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.
+ * jface.viewers.ILabelProviderListener)
+ */
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(org.eclipse
+ * .debug.core.model.IValue, org.eclipse.debug.ui.IValueDetailListener)
+ */
+ @Override
+ public void computeDetail(IValue value, IValueDetailListener listener) {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public Color getBackground(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.
+ * IEditorInput, java.lang.Object)
+ */
+ @Override
+ public String getEditorId(IEditorInput input, Object element) {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object)
+ */
+ @Override
+ public IEditorInput getEditorInput(Object element) {
+
+ return null;
+ }
+
+ @Override
+ public Color getForeground(Object element) {
+
+ if (element instanceof MemoryRenderingElement) {
+ MemoryRenderingElement elm = (MemoryRenderingElement) element;
+ MemoryByte[] bytes = elm.getBytes();
+ if (!bytes[0].isWritable()) {
+ return blue;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang
+ * .Object, java.lang.String)
+ */
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse
+ * .jface.viewers.ILabelProviderListener)
+ */
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.debug.ui.IDebugModelPresentation#setAttribute(java.lang.String
+ * , java.lang.Object)
+ */
+ @Override
+ public void setAttribute(String attribute, Object value) {
+ }
+}

Back to the top