Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Williams2009-02-09 06:20:34 +0000
committerTed Williams2009-02-09 06:20:34 +0000
commit2f1c9049d9be2dd4a6a76f95e01b04f3b56d47dc (patch)
treefe09ee1826b6e998b898b018b614287df20c918c /memory/org.eclipse.cdt.debug.ui.memory.transport
parent49d7a3d05161665add206d5d0280241970072aa4 (diff)
parent8a526a1b6d440e8078cb51f345dfa914615b6a6c (diff)
downloadorg.eclipse.cdt-2f1c9049d9be2dd4a6a76f95e01b04f3b56d47dc.tar.gz
org.eclipse.cdt-2f1c9049d9be2dd4a6a76f95e01b04f3b56d47dc.tar.xz
org.eclipse.cdt-2f1c9049d9be2dd4a6a76f95e01b04f3b56d47dc.zip
[memory] DSDP-DD -> CDT initial commit
Diffstat (limited to 'memory/org.eclipse.cdt.debug.ui.memory.transport')
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath7
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/.project28
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF16
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/about.html24
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/build.properties9
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/icons/export.pngbin0 -> 227 bytes
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/icons/import.pngbin0 -> 236 bytes
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.properties2
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.xml73
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/schema/MemoryTransport.exsd141
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/BufferedMemoryWriter.java83
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ExportMemoryDialog.java202
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java245
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/MemoryTransportPlugin.java64
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/Messages.java33
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java476
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java371
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java465
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java344
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java508
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java441
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ExportMemoryAction.java79
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ImportMemoryAction.java85
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/messages.properties0
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryExporter.java34
-rw-r--r--memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryImporter.java36
27 files changed, 3773 insertions, 0 deletions
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath b/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath
new file mode 100644
index 00000000000..2fbb7a23e12
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/.project b/memory/org.eclipse.cdt.debug.ui.memory.transport/.project
new file mode 100644
index 00000000000..f011d2cff38
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.debug.ui.memory.transport</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs b/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..b51d4342d8d
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Fri May 09 21:44:48 PDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF b/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..4486a9eb402
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Memory Transport Plug-in
+Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.transport;singleton:=true
+Bundle-Version: 1.1.0.qualifier
+Bundle-Localization: plugin
+Bundle-Vendor: Eclipse.org
+Require-Bundle: org.eclipse.debug.core,
+ org.eclipse.debug.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.swt,
+ org.eclipse.jface,
+ org.eclipse.ui
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/about.html b/memory/org.eclipse.cdt.debug.ui.memory.transport/about.html
new file mode 100644
index 00000000000..04492dd7e1b
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>May 14, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ No newline at end of file
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/build.properties b/memory/org.eclipse.cdt.debug.ui.memory.transport/build.properties
new file mode 100644
index 00000000000..835e763df2c
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ schema/,\
+ plugin.xml,\
+ build.properties,\
+ plugin.properties,\
+ icons/
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/export.png b/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/export.png
new file mode 100644
index 00000000000..91b2198825c
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/export.png
Binary files differ
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/import.png b/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/import.png
new file mode 100644
index 00000000000..fa02317c7fd
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/icons/import.png
Binary files differ
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.properties b/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.properties
new file mode 100644
index 00000000000..1ce59a6a290
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.properties
@@ -0,0 +1,2 @@
+ExportMemoryAction.label=Export
+ImportMemoryAction.label=Import \ No newline at end of file
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.xml b/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.xml
new file mode 100644
index 00000000000..98cccbccfb7
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/plugin.xml
@@ -0,0 +1,73 @@
+<?eclipse version="3.0"?>
+<plugin>
+ <extension-point id="memoryTransport" name="memoryTransport" schema="schema/MemoryTransport.exsd"/>
+
+ <extension
+ id="org.eclipse.cdt.debug.ui.memory.transport.dd"
+ name="org.eclipse.cdt.debug.ui.memory.transport.dd"
+ point="org.eclipse.cdt.debug.ui.memory.transport.memoryTransport">
+
+ <importer
+ name="SRecordImporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter">
+ </importer>
+ <exporter
+ name="SRecordExporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter">
+ </exporter>
+
+ <importer
+ name="PlainTextImporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.PlainTextImporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.PlainTextImporter">
+ </importer>
+ <exporter
+ name="PlainTextExporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.PlainTextExporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.PlainTextExporter">
+ </exporter>
+
+ <importer
+ name="RAWBinaryImporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryImporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryImporter">
+ </importer>
+ <exporter
+ name="RAWBInaryExporter"
+ id="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryExporter"
+ class="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryExporter">
+ </exporter>
+
+ </extension>
+
+ <extension point="org.eclipse.ui.viewActions">
+ <viewContribution
+ targetID="org.eclipse.debug.ui.MemoryView"
+ id="org.eclipse.debug.ui.memoryView.toolbar">
+ <action
+ class="org.eclipse.cdt.debug.ui.memory.transport.actions.ExportMemoryAction"
+ enablesFor="1"
+ helpContextId="ExportMemoryAction_context"
+ icon="icons/export.png"
+ id="org.eclipse.cdt.debug.ui.memory.transport.actions.ExportMemoryAction"
+ label="%ExportMemoryAction.label"
+ state="false"
+ style="push"
+ toolbarPath="additions"
+ tooltip="%ExportMemoryAction.label"/>
+ <action
+ class="org.eclipse.cdt.debug.ui.memory.transport.actions.ImportMemoryAction"
+ enablesFor="1"
+ helpContextId="ImportMemoryAction_context"
+ icon="icons/import.png"
+ id="org.eclipse.cdt.debug.ui.memory.transport.actions.ImportMemoryAction"
+ label="%ImportMemoryAction.label"
+ state="false"
+ style="push"
+ toolbarPath="additions"
+ tooltip="%ImportMemoryAction.label"/>
+ </viewContribution>
+ </extension>
+</plugin>
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/schema/MemoryTransport.exsd b/memory/org.eclipse.cdt.debug.ui.memory.transport/schema/MemoryTransport.exsd
new file mode 100644
index 00000000000..6efec619ca9
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/schema/MemoryTransport.exsd
@@ -0,0 +1,141 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.debug.ui.memory.transport" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.cdt.debug.ui.memory.transport" id="memoryTransport" name="memoryTransport"/>
+ </appinfo>
+ <documentation>
+ Allows plug-ins to contribute arbitrary memory importers and exporters.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="exporter">
+ <complexType>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="importer">
+ <complexType>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.0.0
+ </documentation>
+ </annotation>
+
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ /*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/BufferedMemoryWriter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/BufferedMemoryWriter.java
new file mode 100644
index 00000000000..d767bd86183
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/BufferedMemoryWriter.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.math.BigInteger;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+
+public class BufferedMemoryWriter
+{
+ private IMemoryBlockExtension fBlock;
+ private byte[] fBuffer;
+ private int fBufferPosition = 0;
+ private BigInteger fBufferStart = null;
+
+ public BufferedMemoryWriter(IMemoryBlockExtension block, int bufferLength)
+ {
+ fBlock = block;
+ fBuffer = new byte[bufferLength];
+ }
+
+ public void write(BigInteger address, byte[] data) throws DebugException
+ {
+ while(data.length > 0)
+ {
+ if(fBufferStart == null)
+ {
+ fBufferStart = address;
+ int length = data.length <= fBuffer.length ? data.length : fBuffer.length;
+ System.arraycopy(data, 0, fBuffer, 0, length);
+ fBufferPosition = length;
+ byte[] dataRemainder = new byte[data.length - length];
+ System.arraycopy(data, length, dataRemainder, 0, data.length - length);
+ data = dataRemainder;
+ address = fBufferStart.add(BigInteger.valueOf(length));
+ }
+ else if(fBufferStart.add(BigInteger.valueOf(fBufferPosition)).compareTo(address) != 0)
+ {
+ flush();
+ }
+ else
+ {
+ int availableBufferLength = fBuffer.length - fBufferPosition;
+ int length = data.length <= fBuffer.length - availableBufferLength
+ ? data.length : fBuffer.length - availableBufferLength;
+ System.arraycopy(data, 0, fBuffer, fBufferPosition, length);
+ fBufferPosition += length;
+
+ byte[] dataRemainder = new byte[data.length - length];
+ System.arraycopy(data, length, dataRemainder, 0, data.length - length);
+ data = dataRemainder;
+ address = fBufferStart.add(BigInteger.valueOf(length));
+ }
+
+ if(fBufferPosition == fBuffer.length)
+ flush();
+ }
+ }
+
+ public void flush() throws DebugException
+ {
+ if(fBufferStart != null)
+ {
+ byte data[] = new byte[fBufferPosition];
+ System.arraycopy(fBuffer, 0, data, 0, fBufferPosition);
+ fBlock.setValue(fBufferStart, data);
+ fBufferStart = null;
+ }
+ }
+
+}
+
+
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ExportMemoryDialog.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ExportMemoryDialog.java
new file mode 100644
index 00000000000..0301c554a72
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ExportMemoryDialog.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+public class ExportMemoryDialog extends SelectionDialog
+{
+
+ private Combo fFormatCombo;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private Control fCurrentControl = null;
+
+ private IMemoryExporter fFormatExporters[];
+ private String fFormatNames[];
+
+ private Properties fProperties = new Properties();
+
+ public ExportMemoryDialog(Shell parent, IMemoryBlock memoryBlock)
+ {
+ super(parent);
+ super.setTitle("Export Memory");
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+
+ fMemoryBlock = memoryBlock;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.dialogs.SelectionDialog#getResult()
+ */
+ public Object[] getResult() {
+
+ Object[] results = super.getResult();
+
+ if (results != null)
+ {
+ return results;
+ }
+ return new Object[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
+ */
+ protected void cancelPressed() {
+
+ setResult(null);
+
+ super.cancelPressed();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed() {
+ if(fCurrentControl != null)
+ fCurrentControl.dispose();
+ fFormatExporters[fFormatCombo.getSelectionIndex()].exportMemory();
+
+ super.okPressed();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, MemoryTransportPlugin.getUniqueIdentifier() + ".ExportMemoryDialog_context"); //$NON-NLS-1$
+ Composite composite = new Composite(parent, SWT.NONE);
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // format
+
+ Label textLabel = new Label(composite, SWT.NONE);
+ textLabel.setText("Format: ");
+
+ fFormatCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
+
+ FormData data = new FormData();
+ data.top = new FormAttachment(fFormatCombo, 0, SWT.CENTER);
+ textLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(textLabel);
+ fFormatCombo.setLayoutData(data);
+
+ Vector exporters = new Vector();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
+ registry.getExtensionPoint("org.eclipse.cdt.debug.ui.memory.transport.memoryTransport");
+ IConfigurationElement points[] =
+ extensionPoint.getConfigurationElements();
+
+ for (int i = 0; i < points.length; i++)
+ {
+ IConfigurationElement element = points[i];
+ if("exporter".equals(element.getName()))
+ {
+ try
+ {
+ exporters.addElement((IMemoryExporter) element.createExecutableExtension("class"));
+ }
+ catch(Exception e) {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ }
+
+ fFormatExporters = new IMemoryExporter[exporters.size()];
+ fFormatNames = new String[exporters.size()];
+ for(int i = 0; i < fFormatExporters.length; i++)
+ {
+ fFormatExporters[i] = (IMemoryExporter) exporters.elementAt(i);
+ fFormatNames[i] = ((IMemoryExporter) exporters.elementAt(i)).getName();
+ }
+
+ final Composite container = new Composite(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fFormatCombo);
+ data.left = new FormAttachment(0);
+ container.setLayoutData(data);
+
+ fFormatCombo.setItems(fFormatNames);
+
+ fFormatCombo.addSelectionListener(new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if(fCurrentControl != null)
+ fCurrentControl.dispose();
+ fCurrentControl = fFormatExporters[fFormatCombo.getSelectionIndex()].createControl(container,
+ fMemoryBlock, fProperties, ExportMemoryDialog.this);
+ }
+ });
+
+
+ fFormatCombo.select(0);
+ fCurrentControl = fFormatExporters[0].createControl(container,
+ fMemoryBlock, fProperties, ExportMemoryDialog.this);
+
+ return composite;
+ }
+
+ public void setValid(boolean isValid)
+ {
+ getButton(IDialogConstants.OK_ID).setEnabled(isValid);
+ }
+
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java
new file mode 100644
index 00000000000..98574c8a504
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java
@@ -0,0 +1,245 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.math.BigInteger;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.internal.ui.views.memory.MemoryView;
+import org.eclipse.debug.internal.ui.views.memory.RenderingViewPane;
+import org.eclipse.debug.ui.memory.IMemoryRendering;
+import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
+import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.ui.progress.UIJob;
+
+public class ImportMemoryDialog extends SelectionDialog
+{
+
+ private Combo fFormatCombo;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private Control fCurrentControl = null;
+
+ private IMemoryImporter fFormatImporters[];
+ private String fFormatNames[];
+
+ private Properties fProperties = new Properties();
+
+ private MemoryView fMemoryView;
+
+ public ImportMemoryDialog(Shell parent, IMemoryBlock memoryBlock, MemoryView view)
+ {
+ super(parent);
+ super.setTitle("Download to Memory");
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+
+ fMemoryBlock = memoryBlock;
+ fMemoryView = view;
+ }
+
+ protected void scrollRenderings(final BigInteger address)
+ {
+ UIJob job = new UIJob("repositionRenderings"){ //$NON-NLS-1$
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ final IMemoryRenderingContainer containers[] = fMemoryView.getMemoryRenderingContainers();
+ for(int i = 0; i < containers.length; i++)
+ {
+ if(containers[i] instanceof RenderingViewPane)
+ {
+ IMemoryRendering rendering = containers[i].getActiveRendering();
+
+ if(rendering instanceof IRepositionableMemoryRendering)
+ {
+ try
+ {
+ ((IRepositionableMemoryRendering) rendering).goToAddress(address);
+ }
+ catch (DebugException e)
+ {
+ // do nothing
+ }
+ }
+ }
+ }
+
+ return Status.OK_STATUS;
+ }};
+ job.setSystem(true);
+ job.setThread(Display.getDefault().getThread());
+ job.schedule();
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.dialogs.SelectionDialog#getResult()
+ */
+ public Object[] getResult() {
+
+ Object[] results = super.getResult();
+
+ if (results != null)
+ {
+ return results;
+ }
+ return new Object[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
+ */
+ protected void cancelPressed() {
+
+ setResult(null);
+
+ super.cancelPressed();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed() {
+ if(fCurrentControl != null)
+ fCurrentControl.dispose();
+ fFormatImporters[fFormatCombo.getSelectionIndex()].importMemory();
+
+ super.okPressed();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, MemoryTransportPlugin.getUniqueIdentifier() + ".ImportMemoryDialog_context"); //$NON-NLS-1$
+ Composite composite = new Composite(parent, SWT.NONE);
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // format
+
+ Label textLabel = new Label(composite, SWT.NONE);
+ textLabel.setText("Format: ");
+
+ fFormatCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
+
+ FormData data = new FormData();
+ data.top = new FormAttachment(fFormatCombo, 0, SWT.CENTER);
+ textLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(textLabel);
+ fFormatCombo.setLayoutData(data);
+
+ Vector importers = new Vector();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
+ registry.getExtensionPoint("org.eclipse.cdt.debug.ui.memory.transport.memoryTransport");
+ IConfigurationElement points[] =
+ extensionPoint.getConfigurationElements();
+
+ for (int i = 0; i < points.length; i++)
+ {
+ IConfigurationElement element = points[i];
+ if("importer".equals(element.getName()))
+ {
+ try
+ {
+ importers.addElement((IMemoryImporter) element.createExecutableExtension("class"));
+ }
+ catch(Exception e) {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ }
+
+ fFormatImporters = new IMemoryImporter[importers.size()];
+ fFormatNames = new String[importers.size()];
+ for(int i = 0; i < fFormatImporters.length; i++)
+ {
+ fFormatImporters[i] = (IMemoryImporter) importers.elementAt(i);
+ fFormatNames[i] = ((IMemoryImporter) importers.elementAt(i)).getName();
+ }
+
+ final Composite container = new Composite(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fFormatCombo);
+ data.left = new FormAttachment(0);
+ container.setLayoutData(data);
+
+ fFormatCombo.setItems(fFormatNames);
+
+ fFormatCombo.addSelectionListener(new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if(fCurrentControl != null)
+ fCurrentControl.dispose();
+ fCurrentControl = fFormatImporters[fFormatCombo.getSelectionIndex()].createControl(container,
+ fMemoryBlock, fProperties, ImportMemoryDialog.this);
+ }
+ });
+
+ fFormatCombo.select(0);
+ fCurrentControl =
+ fFormatImporters[0].createControl(container,fMemoryBlock, fProperties, ImportMemoryDialog.this);
+
+ return composite;
+ }
+
+ public void setValid(boolean isValid)
+ {
+ getButton(IDialogConstants.OK_ID).setEnabled(isValid);
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/MemoryTransportPlugin.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/MemoryTransportPlugin.java
new file mode 100644
index 00000000000..4449a062dbf
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/MemoryTransportPlugin.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+public class MemoryTransportPlugin extends AbstractUIPlugin
+{
+ private static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui.memory.transport"; //$NON-NLS-1$
+
+ private static MemoryTransportPlugin plugin;
+
+ public MemoryTransportPlugin()
+ {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static MemoryTransportPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the unique identifier for this plugin.
+ */
+ public static String getUniqueIdentifier() {
+ return PLUGIN_ID;
+ }
+
+ /**
+ * Returns the currently active workbench window shell or <code>null</code>
+ * if none.
+ *
+ * @return the currently active workbench window shell or <code>null</code>
+ */
+ public static Shell getShell() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null) {
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ if (windows.length > 0) {
+ return windows[0].getShell();
+ }
+ }
+ else {
+ return window.getShell();
+ }
+ return null;
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/Messages.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/Messages.java
new file mode 100644
index 00000000000..e0d4fdc92a1
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/Messages.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.ui.memory.transport.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java
new file mode 100644
index 00000000000..48d62a568d7
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java
@@ -0,0 +1,476 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.math.BigInteger;
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class PlainTextExporter implements IMemoryExporter {
+
+ File fOutputFile;
+ BigInteger fStartAddress;
+ BigInteger fEndAddress;
+
+ private Text fStartText;
+ private Text fEndText;
+ private Text fLengthText;
+ private Text fFileText;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ExportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ExportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_END, fEndText.getText());
+
+ fStartAddress = getStartAddress();
+ fEndAddress = getEndAddress();
+ fOutputFile = getFile();
+
+ super.dispose();
+ }
+ };
+
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // start address
+
+ Label startLabel = new Label(composite, SWT.NONE);
+ startLabel.setText("Start address: ");
+ FormData data = new FormData();
+ startLabel.setLayoutData(data);
+
+ fStartText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.left = new FormAttachment(startLabel);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ // end address
+
+ Label endLabel = new Label(composite, SWT.NONE);
+ endLabel.setText("End address: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fStartText);
+ endLabel.setLayoutData(data);
+
+ fEndText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(endLabel);
+ data.width = 100;
+ fEndText.setLayoutData(data);
+
+ // length
+
+ Label lengthLabel = new Label(composite, SWT.NONE);
+ lengthLabel.setText("Length: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fEndText);
+ lengthLabel.setLayoutData(data);
+
+ fLengthText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(lengthLabel);
+ data.width = 100;
+ fLengthText.setLayoutData(data);
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fLengthText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock)
+ .getBigBaseAddress(); // FIXME use selection/caret address?
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ if(properties.getProperty(TRANSFER_END) != null)
+ fEndText.setText(properties.getProperty(TRANSFER_END));
+ else
+ fEndText.setText("0x" + startAddress.toString(16));
+
+ fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory export file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ fLengthText.setText(endAddress.subtract(startAddress).toString());
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ fEndText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ getEndAddress();
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ String lengthString = endAddress.subtract(startAddress).toString();
+
+ if(!fLengthText.getText().equals(lengthString))
+ fLengthText.setText(lengthString);
+ }
+ catch(Exception ex)
+ {
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+
+ });
+
+ fLengthText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ BigInteger length = getLength();
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ BigInteger startAddress = getStartAddress();
+ String endString = "0x" + startAddress.add(length).toString(16);
+ if(!fEndText.getText().equals(endString))
+ fEndText.setText(endString);
+ }
+ catch(Exception ex)
+ {
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ fFileText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ composite.pack();
+
+ return composite;
+ }
+
+ public BigInteger getEndAddress()
+ {
+ String text = fEndText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger endAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return endAddress;
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public BigInteger getLength()
+ {
+ String text = fLengthText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger lengthAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return lengthAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ getEndAddress();
+
+ getStartAddress();
+
+ BigInteger length = getLength();
+
+ if(length.compareTo(BigInteger.ZERO) <= 0)
+ isValid = false;
+
+ if(!getFile().getParentFile().exists())
+ isValid = false;
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+
+ }
+
+ public String getId()
+ {
+ return "PlainTextExporter";
+ }
+
+ public String getName()
+ {
+ return "Plain Text";
+ }
+
+ public void exportMemory() {
+ Job job = new Job("Memory Export to Plain Text File"){ //$NON-NLS-1$
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ // FIXME 4 byte default
+
+ BigInteger CELLSIZE = BigInteger.valueOf(4);
+
+ BigInteger COLUMNS = BigInteger.valueOf(5); // FIXME
+
+ BigInteger DATA_PER_LINE = CELLSIZE.multiply(COLUMNS);
+
+ BigInteger transferAddress = fStartAddress;
+
+ FileWriter writer = new FileWriter(fOutputFile);
+
+ BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_LINE);
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ monitor.beginTask("Transferring Data", jobs.intValue());
+
+ BigInteger jobCount = BigInteger.ZERO;
+ while(transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled())
+ {
+ BigInteger length = DATA_PER_LINE;
+ if(fEndAddress.subtract(transferAddress).compareTo(length) < 0)
+ length = fEndAddress.subtract(transferAddress);
+
+ StringBuffer buf = new StringBuffer();
+
+// String transferAddressString = transferAddress.toString(16);
+
+ // future option
+// for(int i = 0; i < 8 - transferAddressString.length(); i++)
+// buf.append("0");
+// buf.append(transferAddressString);
+// buf.append(" "); // TODO tab?
+
+ // data
+
+ for(int i = 0; i < length.divide(CELLSIZE).intValue(); i++)
+ {
+ if(i != 0)
+ buf.append(" ");
+ MemoryByte bytes[] = ((IMemoryBlockExtension) fMemoryBlock).getBytesFromAddress(
+ transferAddress.add(CELLSIZE.multiply(BigInteger.valueOf(i))),
+ CELLSIZE.longValue() / ((IMemoryBlockExtension) fMemoryBlock).getAddressableSize());
+ for(int byteIndex = 0; byteIndex < bytes.length; byteIndex++)
+ {
+ String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
+ if(bString.length() == 1)
+ buf.append("0");
+ buf.append(bString);
+ }
+ }
+
+ writer.write(buf.toString().toUpperCase());
+ writer.write("\n");
+
+ transferAddress = transferAddress.add(length);
+
+ jobCount = jobCount.add(BigInteger.ONE);
+ if(jobCount.compareTo(factor) == 0)
+ {
+ jobCount = BigInteger.ZERO;
+ monitor.worked(1);
+ }
+ }
+
+ writer.close();
+ monitor.done();
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java
new file mode 100644
index 00000000000..2da8b589549
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java
@@ -0,0 +1,371 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.math.BigInteger;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class PlainTextImporter implements IMemoryImporter {
+
+ File fInputFile;
+ BigInteger fStartAddress;
+ boolean fUseCustomAddress;
+ Boolean fScrollToStart;
+
+ private Text fStartText;
+ private Text fFileText;
+
+// private Button fComboRestoreToThisAddress;
+// private Button fComboRestoreToFileAddress;
+
+ private Button fScrollToBeginningOnImportComplete;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ImportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ private static final int BUFFER_LENGTH = 64 * 1024;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ fUseCustomAddress = true;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_SCROLL_TO_START, fScrollToStart.toString());
+
+ fStartAddress = getStartAddress();
+ fInputFile = getFile();
+
+ super.dispose();
+ }
+ };
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+// // restore to file address
+//
+// fComboRestoreToFileAddress = new Button(composite, SWT.RADIO);
+// fComboRestoreToFileAddress.setText("Restore to address specified in the file");
+// //comboRestoreToFileAddress.setLayoutData(data);
+//
+// // restore to this address
+//
+// fComboRestoreToThisAddress = new Button(composite, SWT.RADIO);
+// fComboRestoreToThisAddress.setText("Restore to this address: ");
+ FormData data = new FormData();
+// data.top = new FormAttachment(fComboRestoreToFileAddress);
+// fComboRestoreToThisAddress.setLayoutData(data);
+
+ Label labelStartText = new Label(composite, SWT.NONE);
+ labelStartText.setText("Restore to address: ");
+
+ fStartText = new Text(composite, SWT.NONE);
+ data = new FormData();
+// data.top = new FormAttachment(fComboRestoreToFileAddress);
+ data.left = new FormAttachment(labelStartText);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock)
+ .getBigBaseAddress(); // FIXME use selection/caret address?
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory import file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ validate();
+ }
+
+ });
+ fFileText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+
+ fScrollToBeginningOnImportComplete = new Button(composite, SWT.CHECK);
+ fScrollToBeginningOnImportComplete.setText("Scroll to File Start Address");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton);
+ fScrollToBeginningOnImportComplete.setLayoutData(data);
+
+ composite.pack();
+ parent.pack();
+
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run()
+ {
+ validate();
+ }
+ });
+
+ return composite;
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ getStartAddress();
+ if(!getFile().exists())
+ isValid = false;
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+ }
+
+ public boolean getScrollToStart()
+ {
+ return fScrollToBeginningOnImportComplete.getSelection();
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ public String getId()
+ {
+ return "PlainTextImporter";
+ }
+
+ public String getName()
+ {
+ return "Plain Text";
+ }
+
+ public void importMemory() {
+ Job job = new Job("Memory Import from Plain Text File"){ //$NON-NLS-1$
+
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH);
+
+ BigInteger scrollToAddress = null;
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fInputFile)));
+
+ BigInteger jobs = BigInteger.valueOf(fInputFile.length());
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
+
+ BigInteger jobCount = BigInteger.ZERO;
+ BigInteger recordAddress = fStartAddress;
+ String line = reader.readLine();
+ while(line != null && !monitor.isCanceled())
+ {
+ StringTokenizer st = new StringTokenizer(line, " ");
+ int bytesRead = 0;
+ while(st.hasMoreElements())
+ {
+ String valueString = (String) st.nextElement();
+ int position = 0;
+ byte data[] = new byte[valueString.length() / 2];
+ for(int i = 0; i < data.length; i++)
+ {
+ data[i] = new BigInteger(valueString.substring(position++, position++ + 1), 16).byteValue();
+ }
+
+ if(scrollToAddress == null)
+ scrollToAddress = recordAddress;
+
+ BigInteger writeAddress =
+
+ recordAddress.subtract(((IMemoryBlockExtension)fMemoryBlock).getBigBaseAddress()).add(BigInteger.valueOf(bytesRead));
+
+ memoryWriter.write(writeAddress, data);
+
+ bytesRead += data.length;
+ }
+
+ recordAddress = recordAddress.add(BigInteger.valueOf(bytesRead));
+
+ jobCount = jobCount.add(BigInteger.valueOf(bytesRead));
+ while(jobCount.compareTo(factor) >= 0)
+ {
+ jobCount = jobCount.subtract(factor);
+ monitor.worked(1);
+ }
+
+ line = reader.readLine();
+ }
+
+ memoryWriter.flush();
+ reader.close();
+ monitor.done();
+
+ if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
+ fParentDialog.scrollRenderings(scrollToAddress);
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e) {e.printStackTrace();}
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java
new file mode 100644
index 00000000000..ca15bfdd2a8
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java
@@ -0,0 +1,465 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.math.BigInteger;
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class RAWBinaryExporter implements IMemoryExporter
+{
+ File fOutputFile;
+ BigInteger fStartAddress;
+ BigInteger fEndAddress;
+
+ private Text fStartText;
+ private Text fEndText;
+ private Text fLengthText;
+ private Text fFileText;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ExportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ExportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_END, fEndText.getText());
+
+ fStartAddress = getStartAddress();
+ fEndAddress = getEndAddress();
+ fOutputFile = getFile();
+
+ super.dispose();
+ }
+ };
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // start address
+
+ Label startLabel = new Label(composite, SWT.NONE);
+ startLabel.setText("Start address: ");
+ FormData data = new FormData();
+ startLabel.setLayoutData(data);
+
+ fStartText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.left = new FormAttachment(startLabel);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ // end address
+
+ Label endLabel = new Label(composite, SWT.NONE);
+ endLabel.setText("End address: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fStartText);
+ endLabel.setLayoutData(data);
+
+ fEndText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(endLabel);
+ data.width = 100;
+ fEndText.setLayoutData(data);
+
+ // length
+
+ Label lengthLabel = new Label(composite, SWT.NONE);
+ lengthLabel.setText("Length: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fEndText);
+ lengthLabel.setLayoutData(data);
+
+ fLengthText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(lengthLabel);
+ data.width = 100;
+ fLengthText.setLayoutData(data);
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fLengthText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ if(properties.getProperty(TRANSFER_END) != null)
+ fEndText.setText(properties.getProperty(TRANSFER_END));
+ else
+ fEndText.setText("0x" + startAddress.toString(16));
+
+ fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory export file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ fLengthText.setText(endAddress.subtract(startAddress).toString());
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ fEndText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ getEndAddress();
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ String lengthString = endAddress.subtract(startAddress).toString();
+
+ if(!fLengthText.getText().equals(lengthString))
+ fLengthText.setText(lengthString);
+ }
+ catch(Exception ex)
+ {
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+
+ });
+
+ fLengthText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ BigInteger length = getLength();
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ BigInteger startAddress = getStartAddress();
+ String endString = "0x" + startAddress.add(length).toString(16);
+ if(!fEndText.getText().equals(endString))
+ fEndText.setText(endString);
+ }
+ catch(Exception ex)
+ {
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ fFileText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ composite.pack();
+ parent.pack();
+
+ /*
+ * We need to perform a validation. If we do it immediately we will get an exception
+ * because things are not totally setup. So we schedule an immediate running of the
+ * validation. For a very brief time the view logically may show a state which does
+ * not reflect the true state of affairs. But the validate immediately corrects the
+ * info. In practice the user never sees the invalid state displayed, because of the
+ * speed of the draw of the dialog.
+ */
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run()
+ {
+ validate();
+ }
+ });
+
+ return composite;
+ }
+
+ public BigInteger getEndAddress()
+ {
+ String text = fEndText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger endAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return endAddress;
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public BigInteger getLength()
+ {
+ String text = fLengthText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger lengthAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return lengthAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ getEndAddress();
+
+ getStartAddress();
+
+ BigInteger length = getLength();
+
+ if(length.compareTo(BigInteger.ZERO) <= 0)
+ isValid = false;
+
+ if(!getFile().getParentFile().exists())
+ isValid = false;
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+ }
+
+
+ public String getId()
+ {
+ return "rawbinary";
+ }
+
+ public String getName()
+ {
+ return "RAW Binary";
+ }
+
+ public void exportMemory()
+ {
+ Job job = new Job("Memory Export to RAW Binary File"){ //$NON-NLS-1$
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ BigInteger DATA_PER_RECORD = BigInteger.valueOf(1024);
+
+ BigInteger transferAddress = fStartAddress;
+
+ FileOutputStream writer = new FileOutputStream(fOutputFile);
+
+ BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD);
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ monitor.beginTask("Transferring Data", jobs.intValue());
+
+ BigInteger jobCount = BigInteger.ZERO;
+ while(transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled())
+ {
+ BigInteger length = DATA_PER_RECORD;
+ if(fEndAddress.subtract(transferAddress).compareTo(length) < 0)
+ length = fEndAddress.subtract(transferAddress);
+
+ // data
+ byte[] byteValues = new byte[length.intValue()];
+
+ MemoryByte bytes[] = ((IMemoryBlockExtension) fMemoryBlock).getBytesFromAddress(transferAddress,
+ length.longValue() / ((IMemoryBlockExtension) fMemoryBlock).getAddressableSize());
+ for(int byteIndex = 0; byteIndex < bytes.length; byteIndex++)
+ {
+ byteValues[byteIndex] = bytes[byteIndex].getValue();
+ }
+
+
+ writer.write(byteValues);
+
+ transferAddress = transferAddress.add(length);
+
+ jobCount = jobCount.add(BigInteger.ONE);
+ if(jobCount.compareTo(factor) == 0)
+ {
+ jobCount = BigInteger.ZERO;
+ monitor.worked(1);
+ }
+ }
+
+ writer.close();
+ monitor.done();
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java
new file mode 100644
index 00000000000..d0270ae962e
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java
@@ -0,0 +1,344 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.math.BigInteger;
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class RAWBinaryImporter implements IMemoryImporter {
+
+ File fInputFile;
+ BigInteger fStartAddress;
+ Boolean fScrollToStart;
+
+ private Text fStartText;
+ private Text fFileText;
+
+ private Button fScrollToBeginningOnImportComplete;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ImportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ private static final int BUFFER_LENGTH = 64 * 1024;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_SCROLL_TO_START, fScrollToStart.toString());
+ fStartAddress = getStartAddress();
+ fInputFile = getFile();
+
+ super.dispose();
+ }
+ };
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // restore to this address
+
+ Label labelStartText = new Label(composite, SWT.NONE);
+ labelStartText.setText("Restore to address: ");
+
+ fStartText = new Text(composite, SWT.NONE);
+ FormData data = new FormData();
+ data.left = new FormAttachment(labelStartText);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory import file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ validate();
+ }
+
+ });
+ fFileText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+
+ fScrollToBeginningOnImportComplete = new Button(composite, SWT.CHECK);
+ fScrollToBeginningOnImportComplete.setText("Scroll to File Start Address");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton);
+ fScrollToBeginningOnImportComplete.setLayoutData(data);
+
+ composite.pack();
+ parent.pack();
+
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run()
+ {
+ validate();
+ }
+ });
+
+ return composite;
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ getStartAddress();
+ if(!getFile().exists())
+ isValid = false;
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+ }
+
+ public boolean getScrollToStart()
+ {
+ return fScrollToBeginningOnImportComplete.getSelection();
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ public String getId()
+ {
+ return "rawbinary";
+ }
+
+ public String getName()
+ {
+ return "RAW Binary";
+ }
+
+ public void importMemory() {
+ Job job = new Job("Memory Import from RAW Binary File"){ //$NON-NLS-1$
+
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH);
+
+ BigInteger scrollToAddress = null;
+
+ FileInputStream reader = new FileInputStream(fInputFile);
+
+ BigInteger jobs = BigInteger.valueOf(fInputFile.length());
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ byte[] byteValues = new byte[1024];
+
+ monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
+
+ BigInteger jobCount = BigInteger.ZERO;
+ int actualByteCount = reader.read(byteValues);
+ BigInteger recordAddress = fStartAddress;
+
+ while(actualByteCount != -1 && !monitor.isCanceled())
+ {
+ byte data[] = new byte[actualByteCount];
+ for(int i = 0; i < data.length; i++)
+ {
+ data[i] = byteValues[i];
+ }
+
+ if(scrollToAddress == null)
+ scrollToAddress = recordAddress;
+
+ BigInteger baseAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ baseAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
+ else
+ baseAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ memoryWriter.write(recordAddress.subtract(baseAddress), data);
+
+ jobCount = jobCount.add(BigInteger.valueOf(actualByteCount));
+ while(jobCount.compareTo(factor) >= 0)
+ {
+ jobCount = jobCount.subtract(factor);
+ monitor.worked(1);
+ }
+
+ recordAddress.add(BigInteger.valueOf(actualByteCount));
+ actualByteCount = reader.read(byteValues);
+ }
+
+ memoryWriter.flush();
+ reader.close();
+ monitor.done();
+
+ if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
+ fParentDialog.scrollRenderings(scrollToAddress);
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java
new file mode 100644
index 00000000000..8e6f61b7c9a
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java
@@ -0,0 +1,508 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.math.BigInteger;
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.debug.core.model.MemoryByte;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SRecordExporter implements IMemoryExporter
+{
+ File fOutputFile;
+ BigInteger fStartAddress;
+ BigInteger fEndAddress;
+
+ private Text fStartText;
+ private Text fEndText;
+ private Text fLengthText;
+ private Text fFileText;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ExportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ExportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_END, fEndText.getText());
+
+ fStartAddress = getStartAddress();
+ fEndAddress = getEndAddress();
+ fOutputFile = getFile();
+
+ super.dispose();
+ }
+ };
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // start address
+
+ Label startLabel = new Label(composite, SWT.NONE);
+ startLabel.setText("Start address: ");
+ FormData data = new FormData();
+ startLabel.setLayoutData(data);
+
+ fStartText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.left = new FormAttachment(startLabel);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ // end address
+
+ Label endLabel = new Label(composite, SWT.NONE);
+ endLabel.setText("End address: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fStartText);
+ endLabel.setLayoutData(data);
+
+ fEndText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(endLabel);
+ data.width = 100;
+ fEndText.setLayoutData(data);
+
+ // length
+
+ Label lengthLabel = new Label(composite, SWT.NONE);
+ lengthLabel.setText("Length: ");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(fEndText);
+ lengthLabel.setLayoutData(data);
+
+ fLengthText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fStartText, 0, SWT.CENTER);
+ data.left = new FormAttachment(lengthLabel);
+ data.width = 100;
+ fLengthText.setLayoutData(data);
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fLengthText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock)
+ .getBigBaseAddress(); // FIXME use selection/caret address?
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ if(properties.getProperty(TRANSFER_END) != null)
+ fEndText.setText(properties.getProperty(TRANSFER_END));
+ else
+ fEndText.setText("0x" + startAddress.toString(16));
+
+ fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory export file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ fLengthText.setText(endAddress.subtract(startAddress).toString());
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ fEndText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ getEndAddress();
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+
+ BigInteger endAddress = getEndAddress();
+ BigInteger startAddress = getStartAddress();
+
+ String lengthString = endAddress.subtract(startAddress).toString();
+
+ if(!fLengthText.getText().equals(lengthString))
+ fLengthText.setText(lengthString);
+ }
+ catch(Exception ex)
+ {
+ fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {}
+
+ });
+
+ fLengthText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ try
+ {
+ BigInteger length = getLength();
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ BigInteger startAddress = getStartAddress();
+ String endString = "0x" + startAddress.add(length).toString(16);
+ if(!fEndText.getText().equals(endString))
+ fEndText.setText(endString);
+ }
+ catch(Exception ex)
+ {
+ fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ }
+
+ validate();
+ }
+
+
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ fFileText.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ validate();
+ }
+
+ public void keyPressed(KeyEvent e) {
+
+ }
+ });
+
+ composite.pack();
+ parent.pack();
+
+ /*
+ * We need to perform a validation. If we do it immediately we will get an exception
+ * because things are not totally setup. So we schedule an immediate running of the
+ * validation. For a very brief time the view logically may show a state which does
+ * not reflect the true state of affairs. But the validate immediately corrects the
+ * info. In practice the user never sees the invalid state displayed, because of the
+ * speed of the draw of the dialog.
+ */
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run()
+ {
+ validate();
+ }
+ });
+
+ return composite;
+ }
+
+ public BigInteger getEndAddress()
+ {
+ String text = fEndText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger endAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return endAddress;
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public BigInteger getLength()
+ {
+ String text = fLengthText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger lengthAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return lengthAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ getEndAddress();
+
+ getStartAddress();
+
+ BigInteger length = getLength();
+
+ if(length.compareTo(BigInteger.ZERO) <= 0)
+ isValid = false;
+
+ if(!getFile().getParentFile().exists())
+ isValid = false;
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+ }
+
+
+ public String getId()
+ {
+ return "srecord";
+ }
+
+ public String getName()
+ {
+ return "SRecord";
+ }
+
+ public void exportMemory()
+ {
+ Job job = new Job("Memory Export to S-Record File"){ //$NON-NLS-1$
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ // FIXME 4 byte default
+
+ BigInteger DATA_PER_RECORD = BigInteger.valueOf(16);
+
+ BigInteger transferAddress = fStartAddress;
+
+ FileWriter writer = new FileWriter(fOutputFile);
+
+ BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD);
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ monitor.beginTask("Transferring Data", jobs.intValue());
+
+ BigInteger jobCount = BigInteger.ZERO;
+ while(transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled())
+ {
+ BigInteger length = DATA_PER_RECORD;
+ if(fEndAddress.subtract(transferAddress).compareTo(length) < 0)
+ length = fEndAddress.subtract(transferAddress);
+
+ writer.write("S3"); // FIXME 4 byte address
+
+ StringBuffer buf = new StringBuffer();
+
+ BigInteger sRecordLength = BigInteger.valueOf(4); // address size
+ sRecordLength = sRecordLength.add(length);
+ sRecordLength = sRecordLength.add(BigInteger.ONE); // checksum
+
+ String transferAddressString = transferAddress.toString(16);
+
+ String lengthString = sRecordLength.toString(16);
+ if(lengthString.length() == 1)
+ buf.append("0");
+ buf.append(lengthString);
+ for(int i = 0; i < 8 - transferAddressString.length(); i++)
+ buf.append("0");
+ buf.append(transferAddressString);
+
+ // data
+
+ MemoryByte bytes[] = ((IMemoryBlockExtension) fMemoryBlock).getBytesFromAddress(transferAddress,
+ length.longValue() / ((IMemoryBlockExtension) fMemoryBlock).getAddressableSize());
+ for(int byteIndex = 0; byteIndex < bytes.length; byteIndex++)
+ {
+ String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
+ if(bString.length() == 1)
+ buf.append("0");
+ buf.append(bString);
+ }
+
+ /*
+ * The least significant byte of the one's complement of the sum of the values
+ * represented by the pairs of characters making up the records length, address,
+ * and the code/data fields.
+ */
+ byte checksum = 0;
+
+ for(int i = 0; i < buf.length(); i+=2)
+ {
+ BigInteger value = new BigInteger(buf.substring(i, i+2), 16);
+ checksum += value.byteValue();
+ }
+
+ String bString = BigInteger.valueOf(0xFF - checksum).and(BigInteger.valueOf(0xFF)).toString(16);
+ if(bString.length() == 1)
+ buf.append("0");
+ buf.append(bString);
+
+ writer.write(buf.toString().toUpperCase());
+ writer.write("\n");
+
+ transferAddress = transferAddress.add(length);
+
+ jobCount = jobCount.add(BigInteger.ONE);
+ if(jobCount.compareTo(factor) == 0)
+ {
+ jobCount = BigInteger.ZERO;
+ monitor.worked(1);
+ }
+ }
+
+ writer.close();
+ monitor.done();
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java
new file mode 100644
index 00000000000..4a586c48d8d
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java
@@ -0,0 +1,441 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.math.BigInteger;
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IMemoryBlockExtension;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SRecordImporter implements IMemoryImporter {
+
+ File fInputFile;
+ BigInteger fStartAddress;
+ Boolean fScrollToStart;
+
+ private Text fStartText;
+ private Text fFileText;
+
+ private Button fComboRestoreToThisAddress;
+ private Button fComboRestoreToFileAddress;
+
+ private Button fScrollToBeginningOnImportComplete;
+
+ private IMemoryBlock fMemoryBlock;
+
+ private ImportMemoryDialog fParentDialog;
+
+ private Properties fProperties;
+
+ private static final int BUFFER_LENGTH = 64 * 1024;
+
+ public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog)
+ {
+ fMemoryBlock = memBlock;
+ fParentDialog = parentDialog;
+ fProperties = properties;
+
+ Composite composite = new Composite(parent, SWT.NONE)
+ {
+ public void dispose()
+ {
+ fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
+ fProperties.setProperty(TRANSFER_START, fStartText.getText());
+ fProperties.setProperty(TRANSFER_SCROLL_TO_START, fScrollToStart.toString());
+ fProperties.setProperty(TRANSFER_CUSTOM_START_ADDRESS, "" + fComboRestoreToThisAddress.getSelection());
+
+ fStartAddress = getStartAddress();
+ fInputFile = getFile();
+
+ super.dispose();
+ }
+ };
+ FormLayout formLayout = new FormLayout();
+ formLayout.spacing = 5;
+ formLayout.marginWidth = formLayout.marginHeight = 9;
+ composite.setLayout(formLayout);
+
+ // restore to file address
+
+ fComboRestoreToFileAddress = new Button(composite, SWT.RADIO);
+ fComboRestoreToFileAddress.setSelection(true);
+ fComboRestoreToFileAddress.setText("Restore to address specified in the file");
+ fComboRestoreToFileAddress.setSelection(!new Boolean(properties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "false")).booleanValue());
+ //comboRestoreToFileAddress.setLayoutData(data);
+
+ // restore to this address
+
+ fComboRestoreToThisAddress = new Button(composite, SWT.RADIO);
+ fComboRestoreToThisAddress.setText("Restore to this address: ");
+ fComboRestoreToThisAddress.setSelection(new Boolean(properties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "false")).booleanValue());
+ FormData data = new FormData();
+ data.top = new FormAttachment(fComboRestoreToFileAddress);
+ fComboRestoreToThisAddress.setLayoutData(data);
+
+ fStartText = new Text(composite, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(fComboRestoreToFileAddress);
+ data.left = new FormAttachment(fComboRestoreToThisAddress);
+ data.width = 100;
+ fStartText.setLayoutData(data);
+
+ fComboRestoreToFileAddress.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {}
+
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ }
+ });
+
+ fComboRestoreToThisAddress.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {}
+
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ }
+ });
+
+ // file
+
+ Label fileLabel = new Label(composite, SWT.NONE);
+ fFileText = new Text(composite, SWT.NONE);
+ Button fileButton = new Button(composite, SWT.PUSH);
+
+ fileLabel.setText("File name: ");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ fileLabel.setLayoutData(data);
+
+ data = new FormData();
+ data.top = new FormAttachment(fileButton, 0, SWT.CENTER);
+ data.left = new FormAttachment(fileLabel);
+ data.width = 300;
+ fFileText.setLayoutData(data);
+
+ fileButton.setText("Browse...");
+ data = new FormData();
+ data.top = new FormAttachment(fStartText);
+ data.left = new FormAttachment(fFileText);
+ fileButton.setLayoutData(data);
+
+ fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
+ fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
+ try
+ {
+ BigInteger startAddress = null;
+ if(fMemoryBlock instanceof IMemoryBlockExtension)
+ startAddress = ((IMemoryBlockExtension) fMemoryBlock)
+ .getBigBaseAddress(); // FIXME use selection/caret address?
+ else
+ startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
+
+ if(properties.getProperty(TRANSFER_START) != null)
+ fStartText.setText(properties.getProperty(TRANSFER_START));
+ else
+ fStartText.setText("0x" + startAddress.toString(16));
+
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+
+ fileButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
+ dialog.setText("Choose memory import file");
+ dialog.setFilterExtensions(new String[] { "*.*;*" } );
+ dialog.setFilterNames(new String[] { "All Files" } );
+ dialog.setFileName(fFileText.getText());
+ dialog.open();
+
+ String filename = dialog.getFileName();
+ if(filename != null && filename.length() != 0 )
+ {
+ fFileText.setText(dialog.getFilterPath() + File.separator + filename);
+ }
+
+ validate();
+ }
+
+ });
+
+ fStartText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ boolean valid = true;
+ try
+ {
+ getStartAddress();
+ }
+ catch(Exception ex)
+ {
+ valid = false;
+ }
+
+ fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
+ Display.getDefault().getSystemColor(SWT.COLOR_RED));
+
+ //
+
+ validate();
+ }
+
+ });
+ fFileText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+
+ fScrollToBeginningOnImportComplete = new Button(composite, SWT.CHECK);
+ fScrollToBeginningOnImportComplete.setText("Scroll to File Start Address");
+ data = new FormData();
+ data.top = new FormAttachment(fileButton);
+ fScrollToBeginningOnImportComplete.setLayoutData(data);
+
+ composite.pack();
+ parent.pack();
+
+ Display.getDefault().asyncExec(new Runnable(){
+ public void run()
+ {
+ validate();
+ }
+ });
+
+ return composite;
+ }
+
+ private void validate()
+ {
+ boolean isValid = true;
+
+ try
+ {
+ boolean restoreToAddress = fComboRestoreToThisAddress.getSelection();
+ if ( restoreToAddress ) {
+ getStartAddress();
+ }
+
+ boolean restoreToAddressFromFile = fComboRestoreToFileAddress.getSelection();
+ if ( restoreToAddressFromFile ) {
+ if(!getFile().exists()) {
+ isValid = false;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ isValid = false;
+ }
+
+ fParentDialog.setValid(isValid);
+ }
+
+ public boolean getScrollToStart()
+ {
+ return fScrollToBeginningOnImportComplete.getSelection();
+ }
+
+ public BigInteger getStartAddress()
+ {
+ String text = fStartText.getText();
+ boolean hex = text.startsWith("0x");
+ BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
+ hex ? 16 : 10);
+
+ return startAddress;
+ }
+
+ public File getFile()
+ {
+ return new File(fFileText.getText());
+ }
+
+ public String getId()
+ {
+ return "srecord";
+ }
+
+ public String getName()
+ {
+ return "SRecord";
+ }
+
+ public void importMemory() {
+ Job job = new Job("Memory Import from S-Record File"){ //$NON-NLS-1$
+
+ public IStatus run(IProgressMonitor monitor) {
+
+ try
+ {
+ try
+ {
+ BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH);
+
+ // FIXME 4 byte default
+
+ final int CHECKSUM_LENGTH = 1;
+
+ BigInteger scrollToAddress = null;
+
+ BigInteger offset = null;
+ if(!fProperties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "false").equals("true"))
+ offset = BigInteger.ZERO;
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fInputFile)));
+
+ BigInteger jobs = BigInteger.valueOf(fInputFile.length());
+ BigInteger factor = BigInteger.ONE;
+ if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
+ {
+ factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
+ jobs = jobs.divide(factor);
+ }
+
+ monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
+
+ BigInteger jobCount = BigInteger.ZERO;
+ String line = reader.readLine();
+ while(line != null && !monitor.isCanceled())
+ {
+ String recordType = line.substring(0, 2);
+ int recordCount = Integer.parseInt(line.substring(2, 4), 16);
+ int bytesRead = 4 + recordCount;
+ int position = 4;
+ int addressSize = 0;
+
+ BigInteger recordAddress = null;
+
+ if("S3".equals(recordType)) //$NON-NLS-1$
+ addressSize = 4;
+ else if("S1".equals(recordType)) //$NON-NLS-1$
+ addressSize = 2;
+ else if("S2".equals(recordType)) //$NON-NLS-1$
+ addressSize = 3;
+
+ recordAddress = new BigInteger(line.substring(position, position + addressSize * 2), 16);
+ recordCount -= addressSize;
+ position += addressSize * 2;
+
+ if(offset == null)
+ offset = fStartAddress.subtract(recordAddress);
+
+ recordAddress = recordAddress.add(offset);
+
+ byte data[] = new byte[recordCount - CHECKSUM_LENGTH];
+ for(int i = 0; i < data.length; i++)
+ {
+ data[i] = new BigInteger(line.substring(position++, position++ + 1), 16).byteValue();
+ }
+
+ /*
+ * The least significant byte of the one's complement of the sum of the values
+ * represented by the pairs of characters making up the records length, address,
+ * and the code/data fields.
+ */
+ StringBuffer buf = new StringBuffer(line.substring(2));
+ byte checksum = 0;
+
+ for(int i = 0; i < buf.length(); i+=2)
+ {
+ BigInteger value = new BigInteger(buf.substring(i, i+2), 16);
+ checksum += value.byteValue();
+ }
+
+ /*
+ * Since we included the checksum in the checksum calculation the checksum
+ * ( if correct ) will always be 0xFF which is -1 using the signed byte size
+ * calculation here.
+ */
+ if ( checksum != (byte) -1 ) {
+ reader.close();
+ monitor.done();
+ return new Status( IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), "Checksum failure of line = " + line); //$NON-NLS-1$
+ }
+
+ if(scrollToAddress == null)
+ scrollToAddress = recordAddress;
+
+ // FIXME error on incorrect checksum
+
+ memoryWriter.write(recordAddress.subtract(((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress()), data);
+
+ jobCount = jobCount.add(BigInteger.valueOf(bytesRead));
+ while(jobCount.compareTo(factor) >= 0)
+ {
+ jobCount = jobCount.subtract(factor);
+ monitor.worked(1);
+ }
+
+ line = reader.readLine();
+ }
+
+ memoryWriter.flush();
+ reader.close();
+ monitor.done();
+
+ if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
+ fParentDialog.scrollRenderings(scrollToAddress);
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ }
+ catch(Exception e)
+ {
+ MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
+ DebugException.INTERNAL_ERROR, "Failure", e));
+ }
+ return Status.OK_STATUS;
+ }};
+ job.setUser(true);
+ job.schedule();
+ }
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ExportMemoryAction.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ExportMemoryAction.java
new file mode 100644
index 00000000000..e722e9a906a
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ExportMemoryAction.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport.actions;
+
+import org.eclipse.cdt.debug.ui.memory.transport.ExportMemoryDialog;
+import org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.internal.ui.views.memory.MemoryView;
+import org.eclipse.debug.ui.memory.IMemoryRendering;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * Action for exporting memory.
+ */
+public class ExportMemoryAction implements IViewActionDelegate {
+
+ private MemoryView fView;
+
+ public void init(IViewPart view) {
+ if (view instanceof MemoryView)
+ fView = (MemoryView) view;
+ }
+
+ private IMemoryBlock getMemoryBlock(ISelection selection)
+ {
+ IMemoryBlock memBlock = null;
+
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection strucSel = (IStructuredSelection) selection;
+
+ // return if current selection is empty
+ if (strucSel.isEmpty())
+ return null;
+
+ Object obj = strucSel.getFirstElement();
+
+ if (obj == null)
+ return null;
+
+ if (obj instanceof IMemoryRendering) {
+ memBlock = ((IMemoryRendering) obj).getMemoryBlock();
+ } else if (obj instanceof IMemoryBlock) {
+ memBlock = (IMemoryBlock) obj;
+ }
+ }
+ return memBlock;
+ }
+
+ public void run(IAction action) {
+
+ ISelection selection = fView.getSite().getSelectionProvider()
+ .getSelection();
+ IMemoryBlock memBlock = getMemoryBlock(selection);
+ if(memBlock == null)
+ return;
+ ExportMemoryDialog dialog = new ExportMemoryDialog(MemoryTransportPlugin.getShell(), memBlock);
+ dialog.open();
+
+ dialog.getResult();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ action.setEnabled(getMemoryBlock(selection) != null);
+ }
+
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ImportMemoryAction.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ImportMemoryAction.java
new file mode 100644
index 00000000000..37f81921ae4
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/actions/ImportMemoryAction.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport.actions;
+
+import org.eclipse.cdt.debug.ui.memory.transport.ImportMemoryDialog;
+import org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.internal.ui.views.memory.MemoryView;
+import org.eclipse.debug.ui.memory.IMemoryRendering;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * Action for downloading memory.
+ */
+public class ImportMemoryAction implements IViewActionDelegate {
+
+
+ private MemoryView fView;
+
+ public void init(IViewPart view) {
+ if (view instanceof MemoryView)
+ fView = (MemoryView) view;
+
+// IDebugContextService debugContextService = DebugUITools.getDebugContextManager().getContextService(view.getSite().getWorkbenchWindow());
+// this.
+// debugContextService.getActiveContext();
+ }
+
+ private IMemoryBlock getMemoryBlock(ISelection selection)
+ {
+ IMemoryBlock memBlock = null;
+
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection strucSel = (IStructuredSelection) selection;
+
+ // return if current selection is empty
+ if (strucSel.isEmpty())
+ return null;
+
+ Object obj = strucSel.getFirstElement();
+
+ if (obj == null)
+ return null;
+
+ if (obj instanceof IMemoryRendering) {
+ memBlock = ((IMemoryRendering) obj).getMemoryBlock();
+ } else if (obj instanceof IMemoryBlock) {
+ memBlock = (IMemoryBlock) obj;
+ }
+ }
+ return memBlock;
+ }
+
+ public void run(IAction action) {
+
+ ISelection selection = fView.getSite().getSelectionProvider()
+ .getSelection();
+ IMemoryBlock memBlock = getMemoryBlock(selection);
+ if(memBlock == null)
+ return;
+
+ ImportMemoryDialog dialog = new ImportMemoryDialog(MemoryTransportPlugin.getShell(), memBlock, fView);
+ dialog.open();
+
+ dialog.getResult();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ action.setEnabled(getMemoryBlock(selection) != null);
+ }
+
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/messages.properties b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/messages.properties
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/messages.properties
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryExporter.java
new file mode 100644
index 00000000000..d90853b8fce
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryExporter.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport.model;
+
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.ExportMemoryDialog;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public interface IMemoryExporter
+{
+ public static final String TRANSFER_FILE = "File";
+ public static final String TRANSFER_START = "Start";
+ public static final String TRANSFER_END = "End";
+
+ public Control createControl(Composite parent, IMemoryBlock memBlock, Properties properties, ExportMemoryDialog parentDialog);
+
+ public void exportMemory();
+
+ public String getId();
+
+ public String getName();
+}
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryImporter.java
new file mode 100644
index 00000000000..5defe42fc6e
--- /dev/null
+++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/model/IMemoryImporter.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2009 Wind River Systems, Inc. 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:
+ * Ted R Williams (Wind River Systems, Inc.) - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.ui.memory.transport.model;
+
+import java.util.Properties;
+
+import org.eclipse.cdt.debug.ui.memory.transport.ImportMemoryDialog;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public interface IMemoryImporter
+{
+ public static final String TRANSFER_FILE = "File";
+ public static final String TRANSFER_START = "Start";
+ public static final String TRANSFER_END = "End";
+ public static final String TRANSFER_CUSTOM_START_ADDRESS = "CustomStartAddress";
+ public static final String TRANSFER_SCROLL_TO_START = "ScrollToStart";
+
+ public Control createControl(Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog);
+
+ public void importMemory();
+
+ public String getId();
+
+ public String getName();
+}

Back to the top