1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

[memory] DSDP-DD -> CDT initial commit

This commit is contained in:
Ted Williams 2009-02-09 06:20:34 +00:00
commit 2f1c9049d9
67 changed files with 12006 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.debug.ui.memory.search</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Memory Search
Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.search;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.debug.core,
org.eclipse.debug.ui,
org.eclipse.core.runtime,
org.eclipse.swt,
org.eclipse.jface,
org.eclipse.ui,
org.eclipse.search;bundle-version="3.4.0"
Eclipse-LazyStart: true
Bundle-Activator: org.eclipse.cdt.debug.ui.memory.search.MemorySearchPlugin
Bundle-Vendor: Eclipse.org
Import-Package: org.eclipse.debug.ui.memory

View file

@ -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>June 5, 2007</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>

View file

@ -0,0 +1,9 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
plugin.properties,\
.,\
plugin.xml,\
about.html,\
icons/

View file

@ -0,0 +1,41 @@
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.ui.viewActions">
<viewContribution
id="org.eclipse.debug.ui.MemoryView.findNext"
targetID="org.eclipse.debug.ui.MemoryView">
<action
class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
label="Find Next"
menubarPath="additions">
</action>
</viewContribution>
<viewContribution
id="org.eclipse.debug.ui.MemoryView.findReplace"
targetID="org.eclipse.debug.ui.MemoryView">
<action
class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
label="Find/Replace..."
menubarPath="additions">
</action>
</viewContribution>
</extension>
<extension point="org.eclipse.search.searchResultViewPages">
<viewPage
class="org.eclipse.cdt.debug.ui.memory.search.MemorySearchResultsPage"
icon="icons/full/obj16/tsearch_dpdn_obj.gif"
id="org.eclipse.cdt.debug.ui.memory.search.MemorySearchResultsPage"
label="Memory Search Results"
searchResultClass="org.eclipse.cdt.debug.ui.memory.search.MemorySearchResult">
</viewPage>
</extension>
</plugin>

View file

@ -0,0 +1,92 @@
/*******************************************************************************
* 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.search;
import java.util.Properties;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
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.swt.widgets.Shell;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
public class FindAction implements IViewActionDelegate {
private MemoryView fView;
private static Properties fSearchDialogProperties = new Properties();
public void init(IViewPart view) {
if (view instanceof MemoryView)
fView = (MemoryView) view;
}
public void run(IAction action) {
ISelection selection = fView.getSite().getSelectionProvider()
.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection strucSel = (IStructuredSelection) selection;
// return if current selection is empty
if (strucSel.isEmpty())
return;
Object obj = strucSel.getFirstElement();
if (obj == null)
return;
IMemoryBlock memBlock = null;
if (obj instanceof IMemoryRendering) {
memBlock = ((IMemoryRendering) obj).getMemoryBlock();
} else if (obj instanceof IMemoryBlock) {
memBlock = (IMemoryBlock) obj;
}
Shell shell = DebugUIPlugin.getShell();
FindReplaceDialog dialog = new FindReplaceDialog(shell, (IMemoryBlockExtension) memBlock,
fView, (Properties) fSearchDialogProperties);
if(action.getText().equalsIgnoreCase("Find Next"))
{
if(fSearchDialogProperties.getProperty(FindReplaceDialog.SEARCH_ENABLE_FIND_NEXT, "false").equals("true"))
{
dialog.performFindNext();
}
return;
}
else
{
dialog.open();
Object results[] = dialog.getResult();
}
}
}
public void selectionChanged(IAction action, ISelection selection) {
if(action.getText().equalsIgnoreCase("Find Next"))
{
action.setEnabled(fSearchDialogProperties.getProperty(FindReplaceDialog.SEARCH_ENABLE_FIND_NEXT, "false")
.equals("true"));
}
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2008-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.search;
import java.math.BigInteger;
public class MemoryMatch
{
BigInteger fStartAddress;
public BigInteger getStartAddress() {
return fStartAddress;
}
public void setStartAddress(BigInteger startAddress) {
fStartAddress = startAddress;
}
public BigInteger getLength() {
return fLength;
}
public void setLength(BigInteger length) {
fLength = length;
}
BigInteger fLength;
public MemoryMatch(BigInteger startAddress, BigInteger length)
{
fStartAddress = startAddress;
fLength = length;
}
public BigInteger getEndAddress()
{
return getStartAddress().add(getLength());
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* 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.search;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class MemorySearchPlugin extends AbstractUIPlugin
{
private static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui.memory.search"; //$NON-NLS-1$
private static MemorySearchPlugin plugin;
public MemorySearchPlugin()
{
super();
plugin = this;
}
/**
* Returns the shared instance.
*/
public static MemorySearchPlugin getDefault() {
return plugin;
}
/**
* Returns the unique identifier for this plugin.
*/
public static String getUniqueIdentifier() {
return PLUGIN_ID;
}
protected static void logError(String message, Exception e)
{
Status status = new Status(IStatus.ERROR, PLUGIN_ID,
DebugException.INTERNAL_ERROR, message, e);
getDefault().getLog().log(status);
}
}

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* 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.search;
import java.util.Enumeration;
import java.util.Vector;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.ISearchResultListener;
import org.eclipse.search.ui.SearchResultEvent;
public class MemorySearchResult implements ISearchResult
{
private ISearchQuery fQuery;
private String fLabel;
private Vector listeners = new Vector();
private Vector fMatches = new Vector();
public MemorySearchResult(ISearchQuery query, String label)
{
fQuery = query;
fLabel = label;
}
public ImageDescriptor getImageDescriptor() {
return null;
}
public String getLabel() {
return fLabel;
}
public ISearchQuery getQuery() {
return fQuery;
}
public String getTooltip() {
return fLabel;
}
public MemoryMatch[] getMatches()
{
MemoryMatch matches[] = new MemoryMatch[fMatches.size()];
for(int i = 0; i < matches.length; i++)
matches[i] = (MemoryMatch) fMatches.elementAt(i);
return matches;
}
public void addMatch(MemoryMatch address)
{
fMatches.addElement(address);
fireChange();
}
private void fireChange()
{
Enumeration en = listeners.elements();
while(en.hasMoreElements())
((ISearchResultListener) en.nextElement()).searchResultChanged(new SearchResultEvent(this) {} );
}
public void addListener(ISearchResultListener l) {
listeners.addElement(l);
}
public void removeListener(ISearchResultListener l) {
listeners.removeElement(l);
}
}

View file

@ -0,0 +1,302 @@
/*******************************************************************************
* 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.search;
import java.lang.reflect.Method;
import java.math.BigInteger;
import org.eclipse.cdt.debug.ui.memory.search.FindReplaceDialog.IMemorySearchQuery;
import org.eclipse.debug.core.DebugException;
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.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.search.ui.IQueryListener;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.ISearchResultListener;
import org.eclipse.search.ui.ISearchResultPage;
import org.eclipse.search.ui.ISearchResultViewPart;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.SearchResultEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
public class MemorySearchResultsPage extends Page implements ISearchResultPage, IQueryListener {
private TreeViewer fTreeViewer;
private PageBook fPagebook;
private Composite fViewerContainer;
private IQueryListener fQueryListener;
private ISearchResultViewPart fPart;
public void queryAdded(ISearchQuery query) {
}
public void queryFinished(ISearchQuery query) {
}
public void queryRemoved(ISearchQuery query) {
}
public void queryStarting(ISearchQuery query) {
}
public String getID() {
return MemorySearchPlugin.getUniqueIdentifier();
}
public String getLabel() {
if(fQuery == null)
return Messages.getString("MemorySearchResultsPage.LabelMemorySearch"); //$NON-NLS-1$
else
return fQuery.getLabel();
}
public Object getUIState() {
return fTreeViewer.getSelection();
}
public void restoreState(IMemento memento) {
}
public void saveState(IMemento memento) {
}
public void setID(String id) {
}
public void setInput(ISearchResult search, Object uiState) {
if(search instanceof MemorySearchResult)
((MemorySearchResult) search).addListener(new ISearchResultListener()
{
public void searchResultChanged(SearchResultEvent e) {
Display.getDefault().asyncExec(new Runnable() {
public void run()
{
fTreeViewer.refresh();
}
});
}
});
}
public void setViewPart(ISearchResultViewPart part) {
fPart = part;
}
public void createControl(Composite parent) {
fViewerContainer = new Composite(parent, SWT.NULL);
fViewerContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
fViewerContainer.setSize(100, 100);
fViewerContainer.setLayout(new FillLayout());
fTreeViewer = new TreeViewer(fViewerContainer, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
fTreeViewer.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
viewer.refresh();
}
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return false;
}
public Object[] getElements(Object inputElement) {
if(fQuery == null)
return new Object[0];
else
{
return ((MemorySearchResult) fQuery.getSearchResult()).getMatches();
}
}
});
fTreeViewer.setInput(new Object());
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener(){
public void selectionChanged(final SelectionChangedEvent event) {
if( event.getSelection() instanceof StructuredSelection)
{
IMemoryRenderingContainer containers[] = ((IMemorySearchQuery) fQuery).getMemoryView().getMemoryRenderingContainers();
MemoryMatch match = (MemoryMatch) ((StructuredSelection) event.getSelection()).getFirstElement();
for(int i = 0; i < containers.length; i++)
{
IMemoryRendering rendering = containers[i].getActiveRendering();
if(rendering instanceof IRepositionableMemoryRendering)
{
try {
((IRepositionableMemoryRendering) rendering).goToAddress(match.getStartAddress());
} catch (DebugException e) {
MemorySearchPlugin.logError(Messages.getString("MemorySearchResultsPage.RepositioningMemoryViewFailed"), e); //$NON-NLS-1$
}
}
if(rendering != null)
{
// Temporary, until platform accepts/adds new interface for setting the selection
try {
Method m = rendering.getClass().getMethod("setSelection", new Class[] { BigInteger.class, BigInteger.class } ); //$NON-NLS-1$
if(m != null)
m.invoke(rendering, match.getStartAddress(), match.getEndAddress());
} catch (Exception e) {
// do nothing
}
}
}
}
}
});
fTreeViewer.setLabelProvider(new ILabelProvider() {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
if(element instanceof MemoryMatch)
return "0x" + ((MemoryMatch) element).getStartAddress().toString(16); //$NON-NLS-1$
return element.toString();
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
fQueryListener = createQueryListener();
NewSearchUI.addQueryListener(fQueryListener);
}
private ISearchQuery fQuery;
private IQueryListener createQueryListener() {
return new IQueryListener() {
public void queryAdded(ISearchQuery query) {
// ignore
}
public void queryRemoved(ISearchQuery query) {
queryStarting(query);
}
public void queryStarting(final ISearchQuery query) {
fQuery = query;
Display.getDefault().asyncExec(new Runnable() {
public void run()
{
fPart.updateLabel();
if(!fTreeViewer.getControl().isDisposed())
fTreeViewer.refresh();
}
});
}
public void queryFinished(final ISearchQuery query) {
}
};
}
public void dispose() {
fTreeViewer.getControl().dispose();
fViewerContainer.dispose();
}
public Control getControl() {
return fViewerContainer;
}
public void setActionBars(IActionBars actionBars) {
}
public void setFocus() {
}
}

View file

@ -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.search;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.ui.memory.search.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 + '!';
}
}
}

View file

@ -0,0 +1,31 @@
FindReplaceDialog.Title=Find / Replace Memory
FindReplaceDialog.ButtonFind=Find
FindReplaceDialog.ButtonFindAll=Find All
FindReplaceDialog.ButtonReplaceFind=Replace/Find
FindReplaceDialog.ButtonReplace=Replace
FindReplaceDialog.ButtonReplaceAll=Replace All
FindReplaceDialog.Close=Close
FindReplaceDialog.LabelFind=Find:
FindReplaceDialog.LabelReplaceWith=Replace With:
FindReplaceDialog.LabelDirection=Direction
FindReplaceDialog.ButtonForward=Forward
FindReplaceDialog.ButtonBackward=Backward
FindReplaceDialog.LabelRange=Range
FindReplaceDialog.LabelStartAddress=Start address:
FindReplaceDialog.LabelEndAddress=End address:
FindReplaceDialog.LabelFormat=Format
FindReplaceDialog.ButtonASCII=ASCII String
FindReplaceDialog.ButtonHexadecimal=Hexadecimal
FindReplaceDialog.ButtonOctal=Octal
FindReplaceDialog.ButtonBinary=Binary
FindReplaceDialog.ButtonDecimal=Decimal
FindReplaceDialog.ButtonByteSequence=Byte Sequence
FindReplaceDialog.LabelOptions=Options
FindReplaceDialog.ButtonWrapSearch=Wrap Search
FindReplaceDialog.ButtonCaseInsensitive=Case Insensitive
FindReplaceDialog.MemoryReadFailed=Memory Read Failed
FindReplaceDialog.MemorySearchFailure=Memory Search Failure
FindReplaceDialog.RepositioningMemoryViewFailed=Repositioning Memory View Failed
FindReplaceDialog.SearchingMemoryFor=Searching memory for
MemorySearchResultsPage.LabelMemorySearch=Memory Search
MemorySearchResultsPage.RepositioningMemoryViewFailed=Repositioning Memory View Failed

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.debug.ui.memory.traditional</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>

View file

@ -0,0 +1,16 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Traditional Memory Rendering
Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.traditional;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.debug.core,
org.eclipse.debug.ui,
org.eclipse.core.runtime,
org.eclipse.swt,
org.eclipse.jface,
org.eclipse.ui,
org.eclipse.search;bundle-version="3.4.0"
Eclipse-LazyStart: true
Bundle-Activator: org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingPlugin
Bundle-Vendor: Eclipse.org

View file

@ -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>June 5, 2007</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>

View file

@ -0,0 +1,9 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
plugin.properties,\
.,\
plugin.xml,\
about.html,\
icons/

View file

@ -0,0 +1 @@
TraditionalRenderingPreferenceActionName=Traditional Rendering Preferences...

View file

@ -0,0 +1,58 @@
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.debug.ui.memoryRenderings">
<renderingType
name="Traditional"
id="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRendering"
class="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingTypeDelegate">
</renderingType>
<renderingBindings
renderingIds="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRendering"
defaultIds="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRendering">
<enablement>
<instanceof value="org.eclipse.debug.core.model.IMemoryBlockExtension"/>
</enablement>
</renderingBindings>
</extension>
<extension point="org.eclipse.debug.ui.memoryRenderings">
<renderingType
name="Traditional Go To Address"
id="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalGoToAddressRendering"
class="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalGoToAddressRenderingTypeDelegate">
</renderingType>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.debug.ui.DebugPreferencePage"
class="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingPreferencePage"
id="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingPreferencePage"
helpContextId="TraditionalRenderingPreferencePage_context"
name="Traditional Memory Rendering"/>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingPreferenceInitializer"/>
</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.traditional.TraditionalRenderingPreferenceAction"
helpContextId="TraditionalRenderingPreferenceAction_context"
id="org.eclipse.cdt.debug.ui.memory.traditional.preferenceaction"
label="%TraditionalRenderingPreferenceActionName"
menubarPath="additions"
style="push"
tooltip="%TraditionalRenderingPreferenceActionName"/>
</viewContribution>
</extension>
</plugin>

View file

@ -0,0 +1,759 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.MemoryByte;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Caret;
public abstract class AbstractPane extends Canvas
{
protected Rendering fRendering;
// selection state
protected boolean fSelectionStarted = false;
protected boolean fSelectionInProgress = false;
protected BigInteger fSelectionStartAddress = null;
protected int fSelectionStartAddressSubPosition;
// caret
protected Caret fCaret = null;
// character may not fall on byte boundary
protected int fSubCellCaretPosition = 0;
protected int fOldSubCellCaretPosition = 0;
protected boolean fCaretEnabled = false;
protected BigInteger fCaretAddress = null;
// storage
protected int fRowCount = 0;
protected boolean fPaneVisible = true;
class AbstractPaneMouseListener implements MouseListener
{
public void mouseUp(MouseEvent me)
{
positionCaret(me.x, me.y);
fCaret.setVisible(true);
if(fSelectionInProgress && me.button == 1)
{
endSelection(me.x, me.y);
}
fSelectionInProgress = fSelectionStarted = false;
}
public void mouseDown(MouseEvent me)
{
AbstractPane.this.forceFocus();
positionCaret(me.x, me.y);
fCaret.setVisible(false);
if(me.button == 1)
{
// if shift is down and we have an existing start address,
// append selection
if((me.stateMask & SWT.SHIFT) != 0
&& fRendering.getSelection().getStart() != null)
{
// if the pane doesn't have a selection start (the
// selection was created in a different pane)
// then initialize the pane's selection start to the
// rendering's selection start
if(AbstractPane.this.fSelectionStartAddress == null)
AbstractPane.this.fSelectionStartAddress = fRendering
.getSelection().getStart();
AbstractPane.this.fSelectionStarted = true;
AbstractPane.this.appendSelection(me.x, me.y);
}
else
{
// start a new selection
AbstractPane.this.startSelection(me.x, me.y);
}
}
}
public void mouseDoubleClick(MouseEvent me)
{
handleMouseDoubleClick(me);
}
}
class AbstractPaneMouseMoveListener implements MouseMoveListener
{
public void mouseMove(MouseEvent me)
{
if(fSelectionStarted)
{
fSelectionInProgress = true;
appendSelection(me.x, me.y);
}
}
}
class AbstractPaneKeyListener implements KeyListener
{
public void keyPressed(KeyEvent ke)
{
fOldSubCellCaretPosition = fSubCellCaretPosition;
if((ke.stateMask & SWT.SHIFT) != 0)
{
switch(ke.keyCode)
{
case SWT.ARROW_RIGHT:
case SWT.ARROW_LEFT:
case SWT.ARROW_UP:
case SWT.ARROW_DOWN:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
if(fRendering.getSelection().getStart() == null)
{
fRendering.getSelection().setStart(fCaretAddress.add(BigInteger.valueOf(
fRendering.getAddressesPerColumn())), fCaretAddress);
}
break;
}
}
if(ke.keyCode == SWT.ARROW_RIGHT)
{
handleRightArrowKey();
}
else if(ke.keyCode == SWT.ARROW_LEFT || ke.keyCode == SWT.BS)
{
handleLeftArrowKey();
}
else if(ke.keyCode == SWT.ARROW_DOWN)
{
handleDownArrowKey();
}
else if(ke.keyCode == SWT.ARROW_UP)
{
handleUpArrowKey();
}
else if(ke.keyCode == SWT.PAGE_DOWN)
{
handlePageDownKey();
}
else if(ke.keyCode == SWT.PAGE_UP)
{
handlePageUpKey();
}
else if(ke.keyCode == SWT.ESC)
{
fRendering.getViewportCache().clearEditBuffer();
}
else if(ke.character == '\r')
{
fRendering.getViewportCache().writeEditBuffer();
}
else if(Rendering.isValidEditCharacter(ke.character))
{
if(fRendering.getSelection().hasSelection())
{
setCaretAddress(fRendering.getSelection().getLow());
fSubCellCaretPosition = 0;
}
editCell(fCaretAddress, fSubCellCaretPosition, ke.character);
}
if((ke.stateMask & SWT.SHIFT) != 0)
{
switch(ke.keyCode)
{
case SWT.ARROW_RIGHT:
case SWT.ARROW_LEFT:
case SWT.ARROW_UP:
case SWT.ARROW_DOWN:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
fRendering.getSelection().setEnd(fCaretAddress.add(BigInteger.valueOf(
fRendering.getAddressesPerColumn())),
fCaretAddress);
break;
}
}
else if(ke.keyCode != SWT.SHIFT)
// if shift key, keep selection, we might add to it
{
fRendering.getSelection().clear();
}
}
public void keyReleased(KeyEvent ke)
{
// do nothing
}
}
class AbstractPanePaintListener implements PaintListener
{
public void paintControl(PaintEvent pe)
{
AbstractPane.this.paint(pe);
}
}
public AbstractPane(Rendering rendering)
{
super(rendering, SWT.DOUBLE_BUFFERED);
fRendering = rendering;
try
{
fCaretAddress = rendering.getBigBaseAddress();
}
catch(Exception e)
{
// do nothing
}
// pref
this.setFont(fRendering.getFont());
GC gc = new GC(this);
gc.setFont(this.getFont());
fCaret = new Caret(this, SWT.NONE);
fCaret.setSize(1, gc.stringExtent("|").y); //$NON-NLS-1$
gc.dispose();
this.addPaintListener(createPaintListener());
this.addMouseListener(createMouseListener());
this.addMouseMoveListener(createMouseMoveListener());
this.addKeyListener(createKeyListener());
this.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();
if(TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY
.equals(store.getString(TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE)))
{
fRendering.getViewportCache().clearEditBuffer();
}
else
{
fRendering.getViewportCache().writeEditBuffer();
}
// clear the pane local selection start
AbstractPane.this.fSelectionStartAddress = null;
}
public void focusGained(FocusEvent fe)
{
}
});
}
protected MouseListener createMouseListener(){
return new AbstractPaneMouseListener();
}
protected MouseMoveListener createMouseMoveListener(){
return new AbstractPaneMouseMoveListener();
}
protected KeyListener createKeyListener(){
return new AbstractPaneKeyListener();
}
protected PaintListener createPaintListener(){
return new AbstractPanePaintListener();
}
protected void handleRightArrowKey()
{
fSubCellCaretPosition++;
if(fSubCellCaretPosition >= getCellCharacterCount())
{
fSubCellCaretPosition = 0;
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.add(BigInteger
.valueOf(getNumberOfBytesRepresentedByColumn() / fRendering.getAddressableSize()));
if(newCaretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) > 0)
{
fSubCellCaretPosition = getCellCharacterCount();
}
else
{
setCaretAddress(newCaretAddress);
}
}
updateCaret();
ensureCaretWithinViewport();
}
protected void handleLeftArrowKey()
{
fSubCellCaretPosition--;
if(fSubCellCaretPosition < 0)
{
fSubCellCaretPosition = getCellCharacterCount() - 1;
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger
.valueOf(getNumberOfBytesRepresentedByColumn() / fRendering.getAddressableSize()));
if(newCaretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) < 0)
{
fSubCellCaretPosition = 0;
}
else
{
setCaretAddress(newCaretAddress);
}
}
updateCaret();
ensureCaretWithinViewport();
}
protected void handleDownArrowKey()
{
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.add(BigInteger
.valueOf(fRendering.getAddressableCellsPerRow()));
setCaretAddress(newCaretAddress);
updateCaret();
ensureCaretWithinViewport();
}
protected void handleUpArrowKey()
{
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger
.valueOf(fRendering.getAddressableCellsPerRow()));
setCaretAddress(newCaretAddress);
updateCaret();
ensureCaretWithinViewport();
}
protected void handlePageDownKey()
{
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.add(BigInteger
.valueOf(fRendering.getAddressableCellsPerRow()
* (fRendering.getRowCount() - 1)));
setCaretAddress(newCaretAddress);
updateCaret();
ensureCaretWithinViewport();
}
protected void handlePageUpKey()
{
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger
.valueOf(fRendering.getAddressableCellsPerRow()
* (fRendering.getRowCount() - 1)));
setCaretAddress(newCaretAddress);
updateCaret();
ensureCaretWithinViewport();
}
protected void handleMouseDoubleClick(MouseEvent me)
{
try
{
BigInteger address = getViewportAddress(me.x / getCellWidth(), me.y
/ getCellHeight());
fRendering.getSelection().clear();
fRendering.getSelection().setStart(address.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn())), address);
fRendering.getSelection().setEnd(address.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn())), address);
}
catch(DebugException de)
{
// do nothing
}
}
protected boolean isPaneVisible()
{
return fPaneVisible;
}
protected void setPaneVisible(boolean visible)
{
fPaneVisible = visible;
this.setVisible(visible);
}
protected int getNumberOfBytesRepresentedByColumn()
{
return fRendering.getBytesPerColumn();
}
protected void editCell(BigInteger address, int subCellPosition,
char character)
{
// do nothing
}
// Set the caret address
protected void setCaretAddress(BigInteger caretAddress)
{
// Ensure that caret is within the addressable range
if((caretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) >= 0) &&
(caretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) <= 0))
{
fCaretAddress = caretAddress;
}
else if(caretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) < 0)
{
// calculate offset from the beginning of the row
int cellOffset = fCaretAddress.subtract(fRendering.getViewportStartAddress()).intValue();
int row = cellOffset / (fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter());
cellOffset -= row * fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter();
fCaretAddress = fRendering.getMemoryBlockStartAddress().add(
BigInteger.valueOf(cellOffset / fRendering.getAddressableSize()));
}
else if(caretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) > 0)
{
// calculate offset from the end of the row
int cellOffset = fCaretAddress.subtract(fRendering.getViewportEndAddress()).intValue() + 1;
int row = cellOffset / (fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter());
cellOffset -= row * fRendering.getBytesPerRow()/ fRendering.getBytesPerCharacter();
fCaretAddress = fRendering.getMemoryBlockEndAddress().add(
BigInteger.valueOf(cellOffset / fRendering.getAddressableSize()));
}
fRendering.setCaretAddress(fCaretAddress);
}
protected boolean isOdd(int value)
{
return (value / 2) * 2 == value;
}
protected void updateCaret()
{
try
{
if(fCaretAddress != null)
{
Point cellPosition = getCellLocation(fCaretAddress);
if(cellPosition != null)
{
fCaret.setLocation(cellPosition.x + fSubCellCaretPosition
* getCellCharacterWidth(), cellPosition.y);
}
}
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
protected void ensureCaretWithinViewport() // TODO getAddressableSize() > 1 ?
{
// determine if caret is before the viewport start
// if so, scroll viewport up by appropriate rows
if(fCaretAddress.compareTo(fRendering.getViewportStartAddress()) < 0)
{
BigInteger difference = fRendering.getViewportStartAddress()
.subtract(fCaretAddress);
BigInteger rows = difference.divide(BigInteger.valueOf(fRendering.getBytesPerRow()));
if(rows.multiply(
BigInteger.valueOf(fRendering.getBytesPerRow())).compareTo(difference) != 0)
rows = rows.add(BigInteger.valueOf(1));
fRendering.setViewportStartAddress(fRendering.getViewportStartAddress()
.subtract(rows.multiply(BigInteger.valueOf(fRendering.getBytesPerRow()))));
fRendering.ensureViewportAddressDisplayable();
fRendering.gotoAddress(fRendering.getViewportStartAddress());
}
// determine if caret is after the viewport end
// if so, scroll viewport down by appropriate rows
else if(fCaretAddress.compareTo(fRendering.getViewportEndAddress()) >= 0)
{
BigInteger difference = fCaretAddress.subtract(fRendering
.getViewportEndAddress().subtract(BigInteger.valueOf(1)));
BigInteger rows = difference.divide(BigInteger.valueOf(fRendering.getBytesPerRow()));
if(rows.multiply(
BigInteger.valueOf(fRendering.getBytesPerRow())).compareTo(difference) != 0)
rows = rows.add(BigInteger.valueOf(1));
fRendering.setViewportStartAddress(fRendering.getViewportStartAddress().add(
rows.multiply(BigInteger.valueOf(fRendering.getBytesPerRow()))));
fRendering.ensureViewportAddressDisplayable();
fRendering.gotoAddress(fRendering.getViewportStartAddress());
}
fRendering.setCaretAddress(fCaretAddress);
}
protected void advanceCursor()
{
fSubCellCaretPosition++;
if(fSubCellCaretPosition >= getCellCharacterCount())
{
fSubCellCaretPosition = 0;
fCaretAddress = fCaretAddress.add(BigInteger
.valueOf(getNumberOfBytesRepresentedByColumn() / fRendering.getAddressableSize()));
}
updateCaret();
ensureCaretWithinViewport();
}
protected void positionCaret(int x, int y)
{
// do nothing
}
protected int getRowCount()
{
return fRowCount;
}
protected void setRowCount()
{
fRowCount = getBounds().height / getCellHeight();
}
protected void settingsChanged()
{
fSubCellCaretPosition = 0;
}
protected void startSelection(int x, int y)
{
try
{
BigInteger address = getViewportAddress(x / getCellWidth(), y
/ getCellHeight());
if(address != null)
{
this.fSelectionStartAddress = address;
Point cellPosition = getCellLocation(address);
if(cellPosition != null)
{
int offset = x - cellPosition.x;
fSelectionStartAddressSubPosition = offset
/ getCellCharacterWidth();
}
fRendering.getSelection().clear();
fRendering.getSelection().setStart(address.add(BigInteger.valueOf(
fRendering.getBytesPerColumn() / fRendering.getAddressableSize())), address);
fSelectionStarted = true;
new CopyAction(fRendering, DND.SELECTION_CLIPBOARD).run();
}
}
catch(DebugException e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_START_SELECTION"), e); //$NON-NLS-1$
}
}
protected void endSelection(int x, int y)
{
appendSelection(x, y);
fSelectionInProgress = false;
}
protected void appendSelection(int x, int y)
{
try
{
if(this.fSelectionStartAddress == null)
return;
BigInteger address = getViewportAddress(x / getCellWidth(), y
/ getCellHeight());
if(address.compareTo(this.fSelectionStartAddress) == 0)
{
// deal with sub cell selection
Point cellPosition = getCellLocation(address);
int offset = x - cellPosition.x;
int subCellCharacterPosition = offset / getCellCharacterWidth();
if(Math.abs(subCellCharacterPosition
- this.fSelectionStartAddressSubPosition) > this
.getCellCharacterCount() / 4)
{
fRendering.getSelection().setEnd(address.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn())), address);
}
else
{
fRendering.getSelection().setEnd(null, null);
}
}
else
{
fRendering.getSelection().setEnd(address.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn())), address);
}
if(fRendering.getSelection().getEnd() != null)
{
this.fCaretAddress = fRendering.getSelection().getEnd();
this.fSubCellCaretPosition = 0;
}
updateCaret();
new CopyAction(fRendering, DND.SELECTION_CLIPBOARD).run();
}
catch(DebugException e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_APPEND_SELECTION"), e); //$NON-NLS-1$
}
}
protected void paint(PaintEvent pe)
{
fRowCount = getBounds().height / getCellHeight();
if(fRendering.isDirty())
{
fRendering.setDirty(false);
fRendering.refresh();
}
}
abstract protected BigInteger getViewportAddress(int col, int row)
throws DebugException;
protected Point getCellLocation(BigInteger address)
{
return null;
}
protected String getCellText(MemoryByte bytes[])
{
return null;
}
abstract protected int getCellWidth();
abstract protected int getCellCharacterCount();
public void setFont(Font font)
{
super.setFont(font);
fCharacterWidth = -1;
fCellHeight = -1;
fTextHeight = -1;
}
private int fCellHeight = -1; // called often, cache
protected int getCellHeight()
{
if(fCellHeight == -1)
{
fCellHeight = getCellTextHeight()
+ (fRendering.getCellPadding() * 2);
}
return fCellHeight;
}
private int fCharacterWidth = -1; // called often, cache
protected int getCellCharacterWidth()
{
if(fCharacterWidth == -1)
{
GC gc = new GC(this);
gc.setFont(fRendering.getFont());
fCharacterWidth = gc.getAdvanceWidth('F');
gc.dispose();
}
return fCharacterWidth;
}
private int fTextHeight = -1; // called often, cache
protected int getCellTextHeight()
{
if(fTextHeight == -1)
{
GC gc = new GC(this);
gc.setFont(fRendering.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
fTextHeight = fontMetrics.getHeight();
gc.dispose();
}
return fTextHeight;
}
}

View file

@ -0,0 +1,256 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
public class AddressPane extends AbstractPane
{
public AddressPane(Rendering parent)
{
super(parent);
}
protected BigInteger getViewportAddress(int col, int row)
throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
address = address.add(BigInteger.valueOf((row
* fRendering.getColumnCount() + col)
* fRendering.getAddressesPerColumn()));
return address;
}
protected void appendSelection(int x, int y)
{
try
{
if(this.fSelectionStartAddress == null)
return;
BigInteger address = getViewportAddress(x / getCellWidth(), y
/ getCellHeight());
if(address.compareTo(this.fSelectionStartAddress) == 0)
{
fRendering.getSelection().setEnd(null, null);
}
else
{
fRendering.getSelection().setEnd(address.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn() * fRendering.getColumnCount())), address);
}
}
catch(DebugException e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_APPEND_SELECTION"), e); //$NON-NLS-1$
}
}
public Point computeSize(int wHint, int hHint)
{
return new Point(getCellWidth() + fRendering.getRenderSpacing(), 100);
}
protected int getCellCharacterCount()
{
// two characters per byte of hex address
return fRendering.getAddressBytes() * 2
+ 2; // 0x
}
protected int getCellWidth()
{
GC gc = new GC(this);
StringBuffer buf = new StringBuffer();
for(int i = 0; i < getCellCharacterCount(); i++)
buf.append("0");
int width = gc.textExtent(buf.toString()).x;
gc.dispose();
return width;
}
private int getColumnCount()
{
return 0;
}
private BigInteger getCellAddressAt(int x, int y) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
int col = x / getCellWidth();
int row = y / getCellHeight();
if(col > getColumnCount())
return null;
address = address.add(BigInteger.valueOf(row
* fRendering.getColumnCount() * fRendering.getAddressesPerColumn()
/ fRendering.getBytesPerCharacter()));
address = address.add(BigInteger.valueOf(col
* fRendering.getAddressesPerColumn()));
return address;
}
protected Point getCellLocation(BigInteger cellAddress)
{
try
{
BigInteger address = fRendering.getViewportStartAddress();
int cellOffset = cellAddress.subtract(address).intValue();
cellOffset *= fRendering.getAddressableSize();
if(fRendering.getColumnCount() == 0) // avoid divide by zero
return new Point(0,0);
int row = cellOffset
/ (fRendering.getColumnCount() * fRendering.getBytesPerColumn() / fRendering
.getBytesPerCharacter());
cellOffset -= row * fRendering.getColumnCount()
* fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter();
int col = cellOffset / fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter();
int x = col * getCellWidth() + fRendering.getCellPadding();
int y = row * getCellHeight() + fRendering.getCellPadding();
return new Point(x, y);
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_DETERMINE_CELL_LOCATION"), e); //$NON-NLS-1$
return null;
}
}
protected int getNumberOfBytesRepresentedByColumn()
{
return fRendering.getBytesPerRow();
}
protected void positionCaret(int x, int y)
{
try
{
BigInteger cellAddress = getCellAddressAt(x, y);
if(cellAddress != null)
{
Point cellPosition = getCellLocation(cellAddress);
int offset = x - cellPosition.x;
int x2 = offset / getCellCharacterWidth();
if(x2 >= this.getCellCharacterCount())
{
cellAddress = cellAddress.add(BigInteger.valueOf(this
.getNumberOfBytesRepresentedByColumn()));
x2 = 0;
cellPosition = getCellLocation(cellAddress);
}
fCaret.setLocation(cellPosition.x + x2
* getCellCharacterWidth(), cellPosition.y);
this.fCaretAddress = cellAddress;
this.fSubCellCaretPosition = x2;
setCaretAddress(fCaretAddress);
}
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
protected void paint(PaintEvent pe)
{
super.paint(pe);
GC gc = pe.gc;
FontMetrics fontMetrics = gc.getFontMetrics();
int textHeight = fontMetrics.getHeight();
int cellHeight = textHeight + (fRendering.getCellPadding() * 2);
try
{
BigInteger start = fRendering.getViewportStartAddress();
for(int i = 0; i < this.getBounds().height / cellHeight; i++)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
BigInteger lineAddress = start.add(BigInteger.valueOf(i
* fRendering.getColumnCount()
* fRendering.getAddressesPerColumn()));
if(fRendering.getSelection().isSelected(lineAddress))
{
gc.setBackground(fRendering.getTraditionalRendering().getColorSelection());
gc.fillRectangle(fRendering.getCellPadding() * 2,
cellHeight * i, getCellWidth(), cellHeight);
gc.setForeground(fRendering.getTraditionalRendering().getColorBackground());
}
else
{
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
gc.fillRectangle(fRendering.getCellPadding() * 2,
cellHeight * i, getCellWidth(), cellHeight);
// Allow subclass to override this method to do its own coloring
applyCustomColor(gc);
}
gc.drawText(fRendering.getAddressString(lineAddress),
fRendering.getCellPadding() * 2, cellHeight * i
+ fRendering.getCellPadding());
}
}
catch(Exception e)
{
fRendering.logError(TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
}
}
// Allow subclass to override this method to do its own coloring
protected void applyCustomColor(GC gc)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
}
}

View file

@ -0,0 +1,381 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.MemoryByte;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
public class DataPane extends AbstractPane
{
public DataPane(Rendering parent)
{
super(parent);
}
protected String getCellText(MemoryByte bytes[])
{
return fRendering.getRadixText(bytes, fRendering.getRadix(), fRendering
.isTargetLittleEndian());
}
protected void editCell(BigInteger address, int subCellPosition,
char character)
{
try
{
MemoryByte bytes[] = fRendering.getBytes(fCaretAddress, fRendering
.getBytesPerColumn());
String cellText = getCellText(bytes);
if(cellText == null)
return;
StringBuffer cellTextBuffer = new StringBuffer(cellText);
cellTextBuffer.setCharAt(subCellPosition, character);
BigInteger value = new BigInteger(cellTextBuffer.toString().trim(),
fRendering.getNumericRadix(fRendering.getRadix()));
final boolean isSignedType = fRendering.getRadix() == Rendering.RADIX_DECIMAL_SIGNED;
final boolean isSigned = isSignedType
&& value.compareTo(BigInteger.valueOf(0)) < 0;
int bitCount = value.bitLength();
if(isSignedType)
bitCount++;
if(bitCount > fRendering.getBytesPerColumn() * 8)
return;
int byteLen = fRendering.getBytesPerColumn();
byte[] byteData = new byte[byteLen];
for(int i = 0; i < byteLen; i++)
{
int bits = 255;
if(isSignedType && i == byteLen - 1)
bits = 127;
byteData[i] = (byte) (value.and(BigInteger.valueOf(bits))
.intValue() & bits);
value = value.shiftRight(8);
}
if(isSigned)
byteData[byteLen - 1] |= 128;
if(!fRendering.isDisplayLittleEndian())
{
byte[] byteDataSwapped = new byte[byteData.length];
for(int i = 0; i < byteData.length; i++)
byteDataSwapped[i] = byteData[byteData.length - 1 - i];
byteData = byteDataSwapped;
}
if(byteData.length != bytes.length)
return;
TraditionalMemoryByte bytesToSet[] = new TraditionalMemoryByte[bytes.length];
for(int i = 0; i < byteData.length; i++)
{
bytesToSet[i] = new TraditionalMemoryByte(byteData[i]);
bytesToSet[i].setBigEndian(bytes[i].isBigEndian());
// for embedded, the user wants feedback that the change will be sent to the target,
// even if does not change the value. eventually, maybe we need another color to
// indicate change.
//if(bytes[i].getValue() != byteData[i])
{
bytesToSet[i].setEdited(true);
}
//else
{
// if(bytes[i] instanceof TraditionalMemoryByte)
// bytesToSet[i].setEdited(((TraditionalMemoryByte) bytes[i]).isEdited());
bytesToSet[i].setChanged(bytes[i].isChanged());
}
}
fRendering.getViewportCache().setEditedValue(address, bytesToSet);
advanceCursor();
redraw();
}
catch(Exception e)
{
// do nothing
}
}
protected int getCellWidth()
{
return getCellCharacterCount() * getCellCharacterWidth()
+ (fRendering.getCellPadding() * 2);
}
protected int getCellCharacterCount()
{
return fRendering.getRadixCharacterCount(fRendering.getRadix(),
fRendering.getBytesPerColumn());
}
public Point computeSize(int wHint, int hHint)
{
return new Point(fRendering.getColumnCount() * getCellWidth()
+ fRendering.getRenderSpacing(), 100);
}
private BigInteger getCellAddressAt(int x, int y) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
int col = x / getCellWidth();
int row = y / getCellHeight();
if(col >= fRendering.getColumnCount())
return null;
address = address.add(BigInteger.valueOf(row
* fRendering.getColumnCount() * fRendering.getAddressesPerColumn()));
address = address.add(BigInteger.valueOf(col
* fRendering.getAddressesPerColumn()));
return address;
}
protected Point getCellLocation(BigInteger cellAddress)
{
try
{
BigInteger address = fRendering.getViewportStartAddress();
int cellOffset = cellAddress.subtract(address).intValue();
cellOffset *= fRendering.getAddressableSize();
int row = cellOffset
/ (fRendering.getColumnCount() * fRendering.getBytesPerColumn());
cellOffset -= row * fRendering.getColumnCount()
* fRendering.getBytesPerColumn();
int col = cellOffset / fRendering.getBytesPerColumn();
int x = col * getCellWidth() + fRendering.getCellPadding();
int y = row * getCellHeight() + fRendering.getCellPadding();
return new Point(x, y);
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_DETERMINE_CELL_LOCATION"), e); //$NON-NLS-1$
return null;
}
}
protected void positionCaret(int x, int y)
{
try
{
BigInteger cellAddress = getCellAddressAt(x, y);
if(cellAddress != null)
{
Point cellPosition = getCellLocation(cellAddress);
int offset = x - cellPosition.x;
int subCellCharacterPosition = offset / getCellCharacterWidth();
if(subCellCharacterPosition == this.getCellCharacterCount())
{
cellAddress = cellAddress.add(BigInteger.valueOf(fRendering
.getAddressesPerColumn()));
subCellCharacterPosition = 0;
cellPosition = getCellLocation(cellAddress);
}
fCaret.setLocation(cellPosition.x + subCellCharacterPosition
* getCellCharacterWidth(), cellPosition.y);
this.fCaretAddress = cellAddress;
this.fSubCellCaretPosition = subCellCharacterPosition;
setCaretAddress(fCaretAddress);
}
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
protected BigInteger getViewportAddress(int col, int row)
throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
address = address.add(BigInteger.valueOf((row
* fRendering.getColumnCount() + col)
* fRendering.getAddressesPerColumn()));
return address;
}
protected void paint(PaintEvent pe)
{
super.paint(pe);
// Allow subclasses to override this method to do their own painting
doPaintData(pe);
}
// Allow subclasses to override this method to do their own painting
protected void doPaintData(PaintEvent pe)
{
GC gc = pe.gc;
gc.setFont(fRendering.getFont());
int cellHeight = getCellHeight();
int cellWidth = getCellWidth();
int columns = fRendering.getColumnCount();
try
{
BigInteger start = fRendering.getViewportStartAddress();
for(int i = 0; i < this.getBounds().height / cellHeight; i++)
{
for(int col = 0; col < columns; col++)
{
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
BigInteger cellAddress = start.add(BigInteger.valueOf((i
* fRendering.getColumnCount() + col)
* fRendering.getAddressesPerColumn()));
TraditionalMemoryByte bytes[] = fRendering.getBytes(cellAddress,
fRendering.getBytesPerColumn());
if(fRendering.getSelection().isSelected(cellAddress))
{
gc.setBackground(fRendering.getTraditionalRendering().getColorSelection());
gc.fillRectangle(cellWidth * col
+ fRendering.getCellPadding(), cellHeight * i,
cellWidth, cellHeight);
gc.setForeground(fRendering.getTraditionalRendering().getColorBackground());
}
else
{
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
gc.fillRectangle(cellWidth * col
+ fRendering.getCellPadding(), cellHeight * i,
cellWidth, cellHeight);
// Allow subclasses to override this method to do their own coloring
applyCustomColor(gc, bytes, col);
}
gc.drawText(getCellText(bytes), cellWidth * col
+ fRendering.getCellPadding(), cellHeight * i
+ fRendering.getCellPadding());
BigInteger cellEndAddress = cellAddress.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn()));
cellEndAddress = cellEndAddress.subtract(BigInteger
.valueOf(1));
if(fCaretEnabled)
{
if(cellAddress.compareTo(fCaretAddress) <= 0
&& cellEndAddress.compareTo(fCaretAddress) >= 0)
{
int x = cellWidth * col
+ fRendering.getCellPadding()
+ fSubCellCaretPosition
* this.getCellCharacterWidth();
int y = cellHeight * i
+ fRendering.getCellPadding();
fCaret.setLocation(x, y);
}
}
if(fRendering.isDebug())
gc.drawRectangle(cellWidth * col
+ fRendering.getCellPadding(), cellHeight * i
+ fRendering.getCellPadding(), cellWidth,
cellHeight);
}
}
}
catch(Exception e)
{
fRendering.logError(TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
}
}
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, TraditionalMemoryByte bytes[], int col)
{
// TODO consider adding finer granularity?
boolean anyByteEditing = false;
for(int n = 0; n < bytes.length && !anyByteEditing; n++)
if(bytes[n] instanceof TraditionalMemoryByte)
if(((TraditionalMemoryByte) bytes[n]).isEdited())
anyByteEditing = true;
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
if(anyByteEditing)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorEdit());
}
else
{
boolean isColored = false;
for(int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for(int n = 0; n < bytes.length; n++)
{
if(bytes[n].isChanged(i))
{
if(i == 0)
gc.setForeground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
else
gc.setBackground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
isColored = true;
break;
}
}
}
}
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* 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.traditional;
public interface IMemoryByte {
public boolean isEdited();
public void setEdited(boolean edited);
}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
public interface IMemorySelection
{
public boolean hasSelection();
public boolean isSelected(BigInteger address);
public BigInteger getStart();
public BigInteger getEnd();
public BigInteger getStartLow();
public void setStart(BigInteger high, BigInteger low);
public void setEnd(BigInteger high, BigInteger low);
public BigInteger getHigh();
public BigInteger getLow();
public void clear();
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.MemoryByte;
public interface IViewportCache {
public void dispose();
public void refresh();
public TraditionalMemoryByte[] getBytes(BigInteger address, int bytesRequested) throws DebugException;
public void archiveDeltas();
public void setEditedValue(BigInteger address, TraditionalMemoryByte[] bytes);
public void clearEditBuffer();
public void writeEditBuffer();
public boolean containsEditedCell(BigInteger address);
// private void queueRequest(BigInteger startAddress, BigInteger endAddress);
}

View file

@ -0,0 +1,326 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.MemoryByte;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
public class TextPane extends AbstractPane
{
public TextPane(Rendering parent)
{
super(parent);
}
protected int getCellCharacterCount()
{
return fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter();
}
protected String getCellText(MemoryByte bytes[])
{
return fRendering.formatText(bytes, fRendering
.isTargetLittleEndian(), fRendering.getTextMode());
}
protected void editCell(BigInteger address, int subCellPosition,
char character)
{
try
{
MemoryByte bytes[] = fRendering.getBytes(fCaretAddress, fRendering
.getBytesPerColumn());
String cellText = getCellText(bytes);
if(cellText == null)
return;
StringBuffer cellTextBuffer = new StringBuffer(cellText);
cellTextBuffer.setCharAt(subCellPosition, character);
byte byteData[] = cellTextBuffer.toString().getBytes(fRendering.getCharacterSet(fRendering.getTextMode()));
if(byteData.length != bytes.length)
return;
TraditionalMemoryByte bytesToSet[] = new TraditionalMemoryByte[bytes.length];
for(int i = 0; i < byteData.length; i++)
{
bytesToSet[i] = new TraditionalMemoryByte(byteData[i]);
if(bytes[i].getValue() != byteData[i])
{
bytesToSet[i].setEdited(true);
}
else
{
bytesToSet[i].setChanged(bytes[i].isChanged());
}
}
fRendering.getViewportCache().setEditedValue(address, bytesToSet);
advanceCursor();
redraw();
}
catch(Exception e)
{
// this is ok
}
}
protected int getCellWidth()
{
GC gc = new GC(this);
gc.setFont(fRendering.getFont());
int width = gc.getAdvanceWidth('F');
gc.dispose();
return fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter() * width;
}
public Point computeSize(int wHint, int hHint)
{
return new Point(fRendering.getColumnCount() * getCellWidth()
+ fRendering.getRenderSpacing(), 100);
}
protected Point getCellLocation(BigInteger cellAddress)
{
try
{
BigInteger address = fRendering.getViewportStartAddress();
int cellOffset = cellAddress.subtract(address).intValue();
cellOffset *= fRendering.getAddressableSize();
int row = cellOffset
/ (fRendering.getColumnCount() * fRendering.getBytesPerColumn() / fRendering
.getBytesPerCharacter());
cellOffset -= row * fRendering.getColumnCount()
* fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter();
int col = cellOffset / fRendering.getBytesPerColumn()
/ fRendering.getBytesPerCharacter();
int x = col * getCellWidth() + fRendering.getCellPadding();
int y = row * getCellHeight() + fRendering.getCellPadding();
return new Point(x, y);
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_DETERMINE_CELL_LOCATION"), e); //$NON-NLS-1$
return null;
}
}
private BigInteger getCellAddressAt(int x, int y) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
int col = x / getCellWidth();
int row = y / getCellHeight();
if(col >= fRendering.getColumnCount())
return null;
address = address.add(BigInteger.valueOf(row
* fRendering.getColumnCount() * fRendering.getAddressesPerColumn()
/ fRendering.getBytesPerCharacter()));
address = address.add(BigInteger.valueOf(col
* fRendering.getAddressesPerColumn()));
return address;
}
protected void positionCaret(int x, int y)
{
try
{
BigInteger cellAddress = getCellAddressAt(x, y);
if(cellAddress != null)
{
Point cellPosition = getCellLocation(cellAddress);
int offset = x - cellPosition.x;
int x2 = offset / getCellCharacterWidth();
if(x2 == this.getCellCharacterCount())
{
cellAddress = cellAddress.add(BigInteger.valueOf(fRendering
.getAddressesPerColumn()));
x2 = 0;
cellPosition = getCellLocation(cellAddress);
}
fCaret.setLocation(cellPosition.x + x2
* getCellCharacterWidth(), cellPosition.y);
this.fCaretAddress = cellAddress;
this.fSubCellCaretPosition = x2;
setCaretAddress(fCaretAddress);
}
}
catch(Exception e)
{
fRendering
.logError(
TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
protected BigInteger getViewportAddress(int col, int row)
throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
address = address.add(BigInteger.valueOf((row
* fRendering.getColumnCount() + col)
* fRendering.getAddressesPerColumn()
/ fRendering.getBytesPerCharacter()));
return address;
}
protected void paint(PaintEvent pe)
{
super.paint(pe);
GC gc = pe.gc;
gc.setFont(fRendering.getFont());
int cellHeight = getCellHeight();
int cellWidth = getCellWidth();
final int columns = fRendering.getColumnCount();
final boolean isLittleEndian = fRendering.isTargetLittleEndian();
gc.setForeground(fRendering.getTraditionalRendering().getColorBackground());
gc.fillRectangle(columns * cellWidth, 0, this.getBounds().width, this
.getBounds().height);
try
{
BigInteger start = fRendering.getViewportStartAddress();
for(int i = 0; i < this.getBounds().height / cellHeight; i++)
{
for(int col = 0; col < columns; col++)
{
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
BigInteger cellAddress = start.add(BigInteger.valueOf((i
* columns + col)
* fRendering.getAddressesPerColumn()));
TraditionalMemoryByte bytes[] = fRendering.getBytes(cellAddress,
fRendering.getBytesPerColumn());
if(fRendering.getSelection().isSelected(cellAddress))
{
gc.setBackground(fRendering.getTraditionalRendering().getColorSelection());
gc.fillRectangle(cellWidth * col, cellHeight * i,
cellWidth, cellHeight);
gc.setForeground(fRendering.getTraditionalRendering().getColorBackground());
}
else
{
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
gc.fillRectangle(cellWidth * col, cellHeight * i,
cellWidth, cellHeight);
applyCustomColor(gc, bytes, col);
}
gc.drawText(fRendering.formatText(bytes,
isLittleEndian, fRendering.getTextMode()), cellWidth * col, cellHeight * i
+ fRendering.getCellPadding());
if(fRendering.isDebug())
gc.drawRectangle(cellWidth * col, cellHeight * i
+ fRendering.getCellPadding(), cellWidth,
cellHeight);
}
}
}
catch(Exception e)
{
fRendering.logError(TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
}
}
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, TraditionalMemoryByte bytes[], int col)
{
// TODO consider adding finer granularity?
boolean anyByteEditing = false;
for(int n = 0; n < bytes.length && !anyByteEditing; n++)
if(bytes[n] instanceof TraditionalMemoryByte)
if(((TraditionalMemoryByte) bytes[n]).isEdited())
anyByteEditing = true;
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
if(anyByteEditing)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorEdit());
}
else
{
boolean isColored = false;
for(int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for(int n = 0; n < bytes.length; n++)
{
if(bytes[n].isChanged(i))
{
if(i == 0)
gc.setForeground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
else
gc.setBackground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
isColored = true;
break;
}
}
}
}
}
}

View file

@ -0,0 +1,269 @@
/*******************************************************************************
* 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.traditional;
import java.math.BigInteger;
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.IMemoryBlockRetrievalExtension;
import org.eclipse.debug.internal.ui.DebugUIMessages;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil;
import org.eclipse.debug.internal.ui.views.memory.RenderingViewPane;
import org.eclipse.debug.internal.ui.views.memory.renderings.CreateRendering;
import org.eclipse.debug.ui.memory.AbstractMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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.Text;
import org.eclipse.ui.PlatformUI;
public class TraditionalGoToAddressRendering extends AbstractMemoryRendering {
private IMemoryRenderingSite fSite;
private IMemoryRenderingContainer fContainer;
@Override
public void init(IMemoryRenderingContainer container, IMemoryBlock block) {
super.init(container, block);
fSite = container.getMemoryRenderingSite();
fContainer = container;
}
public TraditionalGoToAddressRendering(String renderingId) {
super(renderingId);
}
private Control fControl;
public Control createControl(Composite parent) {
Composite fGotoAddressContainer = parent;
final GoToAddressWidget fGotoAddress = new GoToAddressWidget();
Control fGotoAddressControl = fGotoAddress.createControl(fGotoAddressContainer);
fControl = fGotoAddressControl;
final Runnable goHandler = new Runnable()
{
public void run()
{
go(fGotoAddress.getExpressionText(), false);
}
};
Button button = fGotoAddress.getButton(IDialogConstants.OK_ID);
if (button != null)
{
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
goHandler.run();
}
});
}
button = fGotoAddress.getButton(GoToAddressWidget.ID_GO_NEW_TAB);
if (button != null)
{
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
go(fGotoAddress.getExpressionText(), true);
}
});
}
fGotoAddress.getExpressionWidget().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR)
goHandler.run();
super.keyPressed(e);
}
});
return fControl;
}
public Control getControl() {
return fControl;
}
private void go(final String expression, final boolean inNewTab)
{
IMemoryRenderingContainer containers[] = fSite.getMemoryRenderingContainers();
for(int i = 0; i < containers.length; i++)
{
if(containers[i] instanceof RenderingViewPane)
{
final IMemoryRenderingContainer container = containers[i];
if(containers[i] != null)
{
final IMemoryRendering activeRendering = containers[i].getActiveRendering();
if(activeRendering != null)
{
new Thread() {
public void run()
{
IMemoryBlock activeMemoryBlock = activeRendering.getMemoryBlock();
IMemoryBlockExtension blockExtension = (IMemoryBlockExtension) activeMemoryBlock.getAdapter(IMemoryBlockExtension.class);
if(inNewTab)
{
try {
final IMemoryRendering rendering = new CreateRendering(container);
IMemoryBlock newBlock = null;
if(activeMemoryBlock.getDebugTarget() instanceof IMemoryBlockRetrievalExtension)
{
newBlock = ((IMemoryBlockRetrievalExtension) activeMemoryBlock.getDebugTarget())
.getExtendedMemoryBlock(expression, activeMemoryBlock.getDebugTarget());
}
else
{
BigInteger newAddress;
if(expression.toUpperCase().startsWith("0X"))
newAddress = new BigInteger(expression.substring(2), 16);
else
newAddress = new BigInteger(expression, 16);
newBlock = activeMemoryBlock.getDebugTarget().getMemoryBlock(newAddress.longValue(),
activeMemoryBlock.getLength());
}
final IMemoryBlock finalNewBlock = newBlock;
Display.getDefault().asyncExec(new Runnable(){
public void run()
{
rendering.init(container, finalNewBlock);
container.addMemoryRendering(rendering);
}
});
} catch (DebugException e) {
MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed,
DebugUIMessages.GoToAddressAction_Address_is_invalid, e);
}
}
else if(activeRendering instanceof IRepositionableMemoryRendering)
{
try
{
if(activeMemoryBlock.getDebugTarget() instanceof IMemoryBlockRetrievalExtension)
{
IMemoryBlockExtension resolveExpressionBlock = ((IMemoryBlockRetrievalExtension) activeMemoryBlock.getDebugTarget())
.getExtendedMemoryBlock(expression, activeMemoryBlock.getDebugTarget());
((IRepositionableMemoryRendering) activeRendering).goToAddress(resolveExpressionBlock.getBigBaseAddress());
}
else
{
BigInteger newAddress;
if(expression.toUpperCase().startsWith("0X"))
newAddress = new BigInteger(expression.substring(2), 16);
else
newAddress = new BigInteger(expression, 16);
((IRepositionableMemoryRendering) activeRendering).goToAddress(newAddress);
}
}
catch(DebugException de)
{
MemoryViewUtil.openError(DebugUIMessages.GoToAddressAction_Go_to_address_failed,
DebugUIMessages.GoToAddressAction_Address_is_invalid, de);
}
}
}
}.start();
}
}
}
}
}
}
class GoToAddressWidget {
private Text fExpression;
private Button fOKButton;
private Button fOKNewTabButton;
private Composite fComposite;
protected static int ID_GO_NEW_TAB = 2000;
/**
* @param parent
* @return
*/
public Control createControl(Composite parent)
{
fComposite = new Composite(parent, SWT.NONE);
PlatformUI.getWorkbench().getHelpSystem().setHelp(fComposite, DebugUIPlugin.getUniqueIdentifier() + ".GoToAddressComposite_context"); //$NON-NLS-1$
GridLayout layout = new GridLayout();
layout.numColumns = 6;
layout.makeColumnsEqualWidth = false;
layout.marginHeight = 0;
layout.marginLeft = 0;
fComposite.setLayout(layout);
fExpression = new Text(fComposite, SWT.SINGLE | SWT.BORDER);
fExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fOKButton = new Button(fComposite, SWT.NONE);
fOKButton.setText("Go");
// fOKNewTabButton = new Button(fComposite, SWT.NONE);
// fOKNewTabButton.setText("New Tab");
return fComposite;
}
public int getHeight()
{
int height = fComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
return height;
}
public Button getButton(int id)
{
if (id == IDialogConstants.OK_ID)
return fOKButton;
if (id == ID_GO_NEW_TAB)
return fOKNewTabButton;
return null;
}
public String getExpressionText()
{
return fExpression.getText().trim();
}
public Text getExpressionWidget()
{
return fExpression;
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingTypeDelegate;
public class TraditionalGoToAddressRenderingTypeDelegate
implements IMemoryRenderingTypeDelegate
{
public IMemoryRendering createRendering(String id) throws CoreException {
return new TraditionalGoToAddressRendering(id);
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* 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.traditional;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class TraditionalRenderingMessages
{
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRendering_messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
private TraditionalRenderingMessages()
{
}
public static String getString(String key)
{
// TODO Auto-generated method stub
try
{
return RESOURCE_BUNDLE.getString(key);
}
catch(MissingResourceException e)
{
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class TraditionalRenderingPlugin extends AbstractUIPlugin
{
private static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui.memory.traditional"; //$NON-NLS-1$
private static TraditionalRenderingPlugin plugin;
public TraditionalRenderingPlugin()
{
super();
plugin = this;
}
/**
* Returns the shared instance.
*/
public static TraditionalRenderingPlugin getDefault() {
return plugin;
}
/**
* Returns the unique identifier for this plugin.
*/
public static String getUniqueIdentifier() {
return PLUGIN_ID;
}
}

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.ActionDelegate;
public class TraditionalRenderingPreferenceAction extends ActionDelegate implements IViewActionDelegate {
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
IPreferencePage page = new TraditionalRenderingPreferencePage();
showPreferencePage("org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRenderingPreferencePage", page); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
public void init(IViewPart view) {
}
protected void showPreferencePage(String id, IPreferencePage page) {
final IPreferenceNode targetNode = new PreferenceNode(id, page);
PreferenceManager manager = new PreferenceManager();
manager.addToRoot(targetNode);
final PreferenceDialog dialog = new PreferenceDialog(DebugUIPlugin.getShell(), manager);
final boolean [] result = new boolean[] { false };
BusyIndicator.showWhile(DebugUIPlugin.getStandardDisplay(), new Runnable() {
public void run() {
dialog.create();
dialog.setMessage(targetNode.getLabelText());
result[0]= (dialog.open() == Window.OK);
}
});
}
}

View file

@ -0,0 +1,45 @@
/*******************************************************************************
* 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.traditional;
/**
* Constant definitions for plug-in preferences
*/
public class TraditionalRenderingPreferenceConstants {
public static final String MEM_COLOR_CHANGED = "memoryColorChanged";
public static final String MEM_USE_GLOBAL_BACKGROUND = "memUseGlobalBackground";
public static final String MEM_COLOR_BACKGROUND = "memoryColorBackground";
public static final String MEM_COLOR_EDIT = "memoryColorEdit";
public static final String MEM_COLOR_TEXT = "memoryColorText";
public static final String MEM_USE_GLOBAL_SELECTION = "memUseGlobalSelection";
public static final String MEM_COLOR_SELECTION = "memoryColorSelection";
public static final String MEM_USE_GLOBAL_TEXT = "memUseGlobalText";
public static final String MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS = "memoryColorScaleTextAlternate";
public static final String MEM_EDIT_BUFFER_SAVE = "memoryEditBufferSave";
public static final String MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY = "saveOnEnterCancelOnFocusLost";
public static final String MEM_EDIT_BUFFER_SAVE_ON_ENTER_OR_FOCUS_LOST = "saveOnEnterOrFocusLost";
public static final String MEM_HISTORY_TRAILS_COUNT = "memoryHistoryTrailsCount";
}

View file

@ -0,0 +1,63 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
/**
* Class used to initialize default preference values.
*/
public class TraditionalRenderingPreferenceInitializer extends AbstractPreferenceInitializer {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IPreferenceStore store = TraditionalRenderingPlugin.getDefault()
.getPreferenceStore();
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_TEXT, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_BACKGROUND, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED, "255,0,0");
Color systemSelection = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_SELECTION, systemSelection.getRed()
+ "," + systemSelection.getGreen() + "," + systemSelection.getBlue());
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS, "5");
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT, "0,255,0");
Color systemText = Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_TEXT, systemText.getRed()
+ "," + systemText.getGreen() + "," + systemText.getBlue());
Color systemBackground = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_BACKGROUND, systemBackground.getRed()
+ "," + systemBackground.getGreen() + "," + systemBackground.getBlue());
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE,
TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT, "1");
}
}

View file

@ -0,0 +1,104 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.ScaleFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
/**
* This class represents a preference page that
* is contributed to the Preferences dialog. By
* subclassing <samp>FieldEditorPreferencePage</samp>, we
* can use the field support built into JFace that allows
* us to create a page that is small and knows how to
* save, restore and apply itself.
* <p>
* This page is used to modify preferences only. They
* are stored in the preference store that belongs to
* the main plug-in class. That way, preferences can
* be accessed directly via the preference store.
*/
public class TraditionalRenderingPreferencePage
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
public TraditionalRenderingPreferencePage() {
super(GRID);
setPreferenceStore(TraditionalRenderingPlugin.getDefault().getPreferenceStore());
setDescription("Traditional Memory Rendering");
}
@Override
public void createControl(Composite parent) {
super.createControl(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), TraditionalRenderingPlugin.getUniqueIdentifier() + ".TraditionalRenderingPreferencePage_context");
}
/**
* Creates the field editors. Field editors are abstractions of
* the common GUI blocks needed to manipulate various types
* of preferences. Each field editor knows how to save and
* restore itself.
*/
public void createFieldEditors() {
addField(new BooleanFieldEditor(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_TEXT,
"Use Global Te&xt Color", getFieldEditorParent()));
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_TEXT,
"&Text Color:", getFieldEditorParent()));
addField(new ScaleFieldEditor(TraditionalRenderingPreferenceConstants.MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS,
"Brighten Alternate Cells", getFieldEditorParent(), 0, 8, 1, 1));
addField(new BooleanFieldEditor(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_BACKGROUND,
"Use Global B&ackground Color", getFieldEditorParent()));
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_BACKGROUND,
"&Background Color:", getFieldEditorParent()));
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED,
"&Changed Color:", getFieldEditorParent()));
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT,
"&Edit Color:", getFieldEditorParent()));
addField(new BooleanFieldEditor(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION,
"Use Global Se&lection Color", getFieldEditorParent()));
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_SELECTION,
"&Selection Color:", getFieldEditorParent()));
addField(new RadioGroupFieldEditor(TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE,
"Edit Buffer", 1, new String[][] { { "Save on E&nter, Cancel on Focus Lost", "saveOnEnterCancelOnFocusLost" },
{ "Save on Enter or Focus L&ost", "saveOnEnterOrFocusLost" } }, getFieldEditorParent()));
addField(new ScaleFieldEditor(TraditionalRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT,
"History &Trail Levels", getFieldEditorParent(), 1, 10, 1, 1));
}
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
public void init(IWorkbench workbench) {
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* 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.traditional;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingTypeDelegate;
public class TraditionalRenderingTypeDelegate
implements IMemoryRenderingTypeDelegate
{
public IMemoryRendering createRendering(String id) throws CoreException {
return new TraditionalRendering(id);
}
}

View file

@ -0,0 +1,49 @@
TraditionalRendering.GO_TO_ADDRESS=Go To Address
TraditionalRendering.RESET_TO_BASE_ADDRESS=Reset To Base Address
TraditionalRendering.REFRESH=Refresh
TraditionalRendering.ADDRESS=Address
TraditionalRendering.BINARY=Binary
TraditionalRendering.TEXT=Text
TraditionalRendering.1_BYTE=1 byte
TraditionalRendering.2_BYTES=2 bytes
TraditionalRendering.4_BYTES=4 bytes
TraditionalRendering.8_BYTES=8 bytes
TraditionalRendering.ISO-8859-1=ISO-8859-1
TraditionalRendering.USASCII=US-ASCII
TraditionalRendering.UTF8=UTF-8
TraditionalRendering.UTF16=UTF-16
TraditionalRendering.BIG=Big
TraditionalRendering.LITTLE=Little
TraditionalRendering.HEX=Hex
TraditionalRendering.DECIMAL_SIGNED=Decimal Signed
TraditionalRendering.DECIMAL_UNSIGNED=Decimal Unsigned
TraditionalRendering.OCTAL=Octal
TraditionalRendering.PANES=Panes
TraditionalRendering.ENDIAN=Endian
TraditionalRendering.CELL_SIZE=Cell Size
TraditionalRendering.RADIX=Radix
TraditionalRendering.RENDERING_NAME=Traditional
TraditionalRendering.FAILURE_RETRIEVE_START_ADDRESS=Failure in retrieving start address.
TraditionalRendering.FAILURE_RETRIEVE_BASE_ADDRESS=Failure in retrieving base address.
TraditionalRendering.CALLED_ON_NON_DISPATCH_THREAD=Called on non-dispatch thread
TraditionalRendering.FAILURE_READ_MEMORY=Failed reading memory.
TraditionalRendering.FAILURE_WRITE_MEMORY=Error writing memory.
TraditionalRendering.FAILURE_DETERMINE_ADDRESS_SIZE=Failed to determine address size.
TraditionalRendering.FAILURE_POSITION_CURSOR=Failed to position cursor.
TraditionalRendering.FAILURE_START_SELECTION=Failed to start selection.
TraditionalRendering.FAILURE_APPEND_SELECTION=Failed to append selection.
TraditionalRendering.FAILURE_DETERMINE_CELL_LOCATION=Failed to determine cell location.
TraditionalRendering.FAILURE_PAINT=Failed to paint.
TraditionalRendering.FAILURE_COPY_OPERATION=Failed copy operation.
TraditionalRendering.COLUMN_COUNT=Columns
TraditionalRendering.COLUMN_COUNT_AUTO=Auto Size to Fill
TraditionalRendering.COLUMN_COUNT_1=1
TraditionalRendering.COLUMN_COUNT_2=2
TraditionalRendering.COLUMN_COUNT_4=4
TraditionalRendering.COLUMN_COUNT_8=8
TraditionalRendering.COLUMN_COUNT_16=16
TraditionalRendering.COLUMN_COUNT_32=32
TraditionalRendering.COLUMN_COUNT_64=64
TraditionalRendering.COLUMN_COUNT_128=128
TraditionalRendering.COLUMN_COUNT_CUSTOM=Custom...
TraditionalRendering.COPY_ADDRESS=Copy Address

View file

@ -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>

View file

@ -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>

View file

@ -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

View file

@ -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

View file

@ -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>

View file

@ -0,0 +1,9 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
schema/,\
plugin.xml,\
build.properties,\
plugin.properties,\
icons/

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

View file

@ -0,0 +1,2 @@
ExportMemoryAction.label=Export
ImportMemoryAction.label=Import

View file

@ -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>

View file

@ -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>

View file

@ -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;
}
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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 + '!';
}
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}

View file

@ -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();
}