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

Bugzilla defects

256775
283586
287540
290710
292059
292120
292293
This commit is contained in:
Randy Rohrbach 2009-10-18 04:53:48 +00:00
parent 6cb229669e
commit 0d66821cc1
14 changed files with 643 additions and 532 deletions

View file

@ -516,7 +516,7 @@
</extension> </extension>
<!-- memory update policy --> <!-- memory update policy
<extension <extension
point="org.eclipse.ui.viewActions"> point="org.eclipse.ui.viewActions">
<viewContribution <viewContribution
@ -557,6 +557,7 @@
</action> </action>
</viewContribution> </viewContribution>
</extension> </extension>
-->
<!-- Debug view context menu contributions --> <!-- Debug view context menu contributions -->
<extension point="org.eclipse.ui.popupMenus"> <extension point="org.eclipse.ui.popupMenus">

View file

@ -70,8 +70,8 @@ import org.eclipse.swt.custom.CTabFolder2Adapter;
import org.eclipse.swt.custom.CTabFolderEvent; import org.eclipse.swt.custom.CTabFolderEvent;
import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
@ -103,6 +103,7 @@ import org.eclipse.ui.progress.WorkbenchJob;
* *
*/ */
@SuppressWarnings("restriction")
public class MemoryBrowser extends ViewPart implements IDebugContextListener, ILaunchListener, IMemoryRenderingSite public class MemoryBrowser extends ViewPart implements IDebugContextListener, ILaunchListener, IMemoryRenderingSite
{ {
public static final String ID = "org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser"; //$NON-NLS-1$ public static final String ID = "org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser"; //$NON-NLS-1$
@ -118,10 +119,11 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
private ArrayList<IMemoryRenderingContainer> fCurrentContainers = new ArrayList<IMemoryRenderingContainer>(); private ArrayList<IMemoryRenderingContainer> fCurrentContainers = new ArrayList<IMemoryRenderingContainer>();
private final static String KEY_RENDERING = "RENDERING"; //$NON-NLS-1$ private final static String KEY_RENDERING = "RENDERING"; //$NON-NLS-1$
private final static String KEY_CONTEXT = "CONTEXT"; //$NON-NLS-1$ private final static String KEY_CONTEXT = "CONTEXT"; //$NON-NLS-1$
private final static String KEY_RETRIEVAL = "RETRIEVAL"; //$NON-NLS-1$ private final static String KEY_MEMORY_BLOCK = "MEMORY"; //$NON-NLS-1$
private final static String KEY_CONTAINER = "CONTAINER"; //$NON-NLS-1$ private final static String KEY_RETRIEVAL = "RETRIEVAL"; //$NON-NLS-1$
private final static String KEY_CONTAINER = "CONTAINER"; //$NON-NLS-1$
public MemoryBrowser() { public MemoryBrowser() {
} }
@ -175,11 +177,10 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
} }
}); });
fGotoAddressBar.getExpressionWidget().addKeyListener(new KeyListener(){ fGotoAddressBar.getExpressionWidget().addSelectionListener(new SelectionListener() {
public void keyPressed(KeyEvent e) {} public void widgetSelected(SelectionEvent e) {}
public void keyReleased(KeyEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
if(e.keyCode == SWT.CR) performGo(false);
performGo(false);
} }
}); });
@ -270,9 +271,12 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
public void launchChanged(ILaunch launch) {} public void launchChanged(ILaunch launch) {}
public void launchRemoved(ILaunch launch) { public void launchRemoved(ILaunch launch) {
IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) launch.getAdapter(IMemoryBlockRetrieval.class)); // For CDT launch is not adaptable to memory rendering, but the debug targets do.
if(retrieval != null) for (IDebugTarget target : launch.getDebugTargets()) {
releaseTabFolder(retrieval); IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) target.getAdapter(IMemoryBlockRetrieval.class));
if(retrieval != null)
releaseTabFolder(retrieval);
}
} }
public IMemoryRenderingContainer getContainer(String id) { public IMemoryRenderingContainer getContainer(String id) {
@ -323,10 +327,8 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
{ {
public void run() public void run()
{ {
IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension) retrieval;
try { try {
IMemoryBlockExtension newBlock = retrievalExtension.getExtendedMemoryBlock(expression, context); BigInteger newBase = getExpressionAddress(retrieval, expression, context);
BigInteger newBase = newBlock.getBigBaseAddress();
if(((IMemoryBlockExtension) rendering.getMemoryBlock()).supportBaseAddressModification()) if(((IMemoryBlockExtension) rendering.getMemoryBlock()).supportBaseAddressModification())
((IMemoryBlockExtension) rendering.getMemoryBlock()).setBaseAddress(newBase); ((IMemoryBlockExtension) rendering.getMemoryBlock()).setBaseAddress(newBase);
rendering.goToAddress(newBase); rendering.goToAddress(newBase);
@ -366,7 +368,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
private CTabFolder createTabFolder(Composite parent) private CTabFolder createTabFolder(Composite parent)
{ {
CTabFolder folder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT); final CTabFolder folder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT);
ColorRegistry reg = JFaceResources.getColorRegistry(); ColorRegistry reg = JFaceResources.getColorRegistry();
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$ Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
@ -376,17 +378,51 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
folder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); folder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
folder.setBorderVisible(true); folder.setBorderVisible(true);
// listener to dispose rendering resources for each closed tab
folder.addCTabFolder2Listener(new CTabFolder2Adapter() { folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) { public void close(CTabFolderEvent event) {
event.doit = false; event.doit = true;
CTabItem item = (CTabItem) event.item; CTabItem item = (CTabItem) event.item;
IMemoryRenderingContainer container = (IMemoryRenderingContainer) item.getData(KEY_CONTAINER); disposeTab(item);
fCurrentContainers.remove( container ); }
});
// listener to dispose rendering resources for all tab items when view part is closed
folder.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
for(CTabItem tab : folder.getItems()) {
disposeTab(tab);
}
folder.removeDisposeListener(this);
} }
}); });
return folder; return folder;
} }
/**
* dispose rendering resources associated with the tab item
* @param item
*/
private void disposeTab(CTabItem item ) {
if (item.isDisposed())
return;
IMemoryRenderingContainer container = (IMemoryRenderingContainer) item.getData(KEY_CONTAINER);
fCurrentContainers.remove( container );
IMemoryRendering rendering = (IMemoryRendering) item.getData(KEY_RENDERING);
// always deactivate rendering before disposing it.
if ( rendering != null ) {
rendering.deactivated();
rendering.dispose();
}
IMemoryBlockExtension block = (IMemoryBlockExtension) item.getData(KEY_MEMORY_BLOCK);
try {
block.dispose();
} catch (DebugException e) {
MemoryBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, MemoryBrowserPlugin.PLUGIN_ID, "Could not dispose memory block", e)); //$NON-NLS-1$
}
}
private CTabItem createTab(CTabFolder tabFolder, int index) { private CTabItem createTab(CTabFolder tabFolder, int index) {
int swtStyle = SWT.CLOSE; int swtStyle = SWT.CLOSE;
CTabItem tab = new CTabItem(tabFolder, swtStyle, index); CTabItem tab = new CTabItem(tabFolder, swtStyle, index);
@ -496,42 +532,36 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
if(context instanceof IAdaptable) if(context instanceof IAdaptable)
{ {
IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) ((IAdaptable) context).getAdapter(IMemoryBlockRetrieval.class)); IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) ((IAdaptable) context).getAdapter(IMemoryBlockRetrieval.class));
if(retrieval != null) if(retrieval != null)
{ {
fGotoAddressBarControl.setVisible(true); fGotoAddressBarControl.setVisible(true);
if(getTabFolder(retrieval) != null) CTabFolder tabFolder = getTabFolder(retrieval);
if(tabFolder != null)
{ {
fStackLayout.topControl = getTabFolder(retrieval); fStackLayout.topControl = tabFolder;
} }
else else
{ {
CTabFolder newFolder = this.createTabFolder(fRenderingsComposite); tabFolder = this.createTabFolder(fRenderingsComposite);
newFolder.addCTabFolder2Listener(new CTabFolder2Adapter() { tabFolder.addSelectionListener(new SelectionListener()
public void close(CTabFolderEvent event) {
event.doit = true;
CTabItem item = (CTabItem) event.item;
IMemoryRenderingContainer container = (IMemoryRenderingContainer) item.getData(KEY_CONTAINER);
fCurrentContainers.remove( container );
}
});
newFolder.addSelectionListener(new SelectionListener()
{ {
public void widgetDefaultSelected(SelectionEvent e) {} public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
getSite().getSelectionProvider().setSelection(new StructuredSelection(((CTabItem) e.item).getData(KEY_RENDERING))); getSite().getSelectionProvider().setSelection(new StructuredSelection(((CTabItem) e.item).getData(KEY_RENDERING)));
} }
}); });
newFolder.setData(KEY_CONTEXT, context); tabFolder.setData(KEY_RETRIEVAL, retrieval);
newFolder.setData(KEY_RETRIEVAL, retrieval);
CTabItem item = createTab(newFolder, 0); CTabItem item = createTab(tabFolder, 0);
populateTabWithRendering(item, retrieval, context); populateTabWithRendering(item, retrieval, context);
setTabFolder(retrieval, newFolder); setTabFolder(retrieval, tabFolder);
fStackLayout.topControl = getTabFolder(retrieval); fStackLayout.topControl = getTabFolder(retrieval);
} }
// update debug context to the new selection
tabFolder.setData(KEY_CONTEXT, context);
} }
else else
{ {
@ -585,19 +615,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
}; };
IMemoryBlock block = null; IMemoryBlock block = createMemoryBlock(retrieval, "0", context);
if(retrieval instanceof IAdaptable)
{
IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension)
((IAdaptable) retrieval).getAdapter(IMemoryBlockRetrievalExtension.class);
if(retrievalExtension != null)
block = retrievalExtension.getExtendedMemoryBlock("0", context); //$NON-NLS-1$
}
if ( block == null ) {
MemoryBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, MemoryBrowserPlugin.PLUGIN_ID, "Extended Memory Block could not be obtained")); //$NON-NLS-1$
return;
}
fCurrentContainers.add(container); fCurrentContainers.add(container);
rendering.init(container, block); rendering.init(container, block);
@ -606,6 +624,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
tab.getParent().setSelection(0); tab.getParent().setSelection(0);
tab.setData(KEY_RENDERING, rendering); tab.setData(KEY_RENDERING, rendering);
tab.setData(KEY_CONTAINER, container); tab.setData(KEY_CONTAINER, container);
tab.setData(KEY_MEMORY_BLOCK, block);
getSite().getSelectionProvider().setSelection(new StructuredSelection(tab.getData(KEY_RENDERING))); getSite().getSelectionProvider().setSelection(new StructuredSelection(tab.getData(KEY_RENDERING)));
updateLabel(tab, rendering); updateLabel(tab, rendering);
@ -648,12 +667,15 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
if(folder != null) if(folder != null)
{ {
for(CTabItem tab : folder.getItems()) { for(CTabItem tab : folder.getItems()) {
IMemoryRenderingContainer container = (IMemoryRenderingContainer) tab.getData(KEY_CONTAINER); disposeTab(tab);
fCurrentContainers.remove( container );
tab.dispose();
} }
} }
fContextFolders.remove(context); fContextFolders.remove(context);
folder.dispose();
if (fStackLayout.topControl.equals(folder)) {
handleUnsupportedSelection();
}
} }
class SelectionProviderAdapter implements ISelectionProvider { class SelectionProviderAdapter implements ISelectionProvider {
@ -689,7 +711,46 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL
}); });
} }
} }
}
/**
* create a memory block
* @param retrieval memory block retrieval.
* @param expression expression to be evaluated to an addressL
* @param context context for evaluating the expression. This is typically
* a debug element.
* @return a memory block based on the given expression and context
* @throws DebugException if unable to retrieve the specified memory
*/
private IMemoryBlockExtension createMemoryBlock(IMemoryBlockRetrieval retrieval, String expression, Object context) throws DebugException {
IMemoryBlockExtension block = null;
if(retrieval instanceof IAdaptable)
{
IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension)
((IAdaptable) retrieval).getAdapter(IMemoryBlockRetrievalExtension.class);
if(retrievalExtension != null)
block = retrievalExtension.getExtendedMemoryBlock(expression, context); //$NON-NLS-1$
}
if ( block == null ) {
throw new DebugException(new Status(Status.ERROR, MemoryBrowserPlugin.PLUGIN_ID, "Extended Memory Block could not be obtained")); //$NON-NLS-1$
}
return block;
}
/**
* Get a memory address for an expression in a given context.
* @param retrieval
* @param expression
* @param context
* @return BigInteger address of the expression
* @throws DebugException
*/
private BigInteger getExpressionAddress(IMemoryBlockRetrieval retrieval, String expression, Object context) throws DebugException {
// Until 257842 issue is solved this is done via IMemoryBlockRetrievalExtension API.
IMemoryBlockExtension newBlock = createMemoryBlock(retrieval, expression, context);
BigInteger address = newBlock.getBigBaseAddress();
newBlock.dispose();
return address;
} }
} }

View file

@ -9,6 +9,7 @@
class="org.eclipse.cdt.debug.ui.memory.search.FindAction" class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1" enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction" id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
helpContextId="FindNextAction_context"
label="%action.label.0" label="%action.label.0"
menubarPath="additions"> menubarPath="additions">
</action> </action>
@ -20,6 +21,7 @@
class="org.eclipse.cdt.debug.ui.memory.search.FindAction" class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1" enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction" id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
helpContextId="FindReplaceAction_context"
label="%action.label.1" label="%action.label.1"
menubarPath="additions"> menubarPath="additions">
</action> </action>
@ -32,6 +34,7 @@
class="org.eclipse.cdt.debug.ui.memory.search.FindAction" class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1" enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction" id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
helpContextId="FindNextAction_context"
label="%action.label.2" label="%action.label.2"
menubarPath="additions"> menubarPath="additions">
</action> </action>
@ -43,6 +46,7 @@
class="org.eclipse.cdt.debug.ui.memory.search.FindAction" class="org.eclipse.cdt.debug.ui.memory.search.FindAction"
enablesFor="1" enablesFor="1"
id="org.eclipse.cdt.debug.ui.memory.search.FindAction" id="org.eclipse.cdt.debug.ui.memory.search.FindAction"
helpContextId="FindReplaceAction_context"
label="%action.label.3" label="%action.label.3"
menubarPath="additions"> menubarPath="additions">
</action> </action>

View file

@ -75,7 +75,6 @@ public class FindReplaceDialog extends SelectionDialog
private Button fReplaceButton; private Button fReplaceButton;
private Button fReplaceFindButton; private Button fReplaceFindButton;
private Button fReplaceAllButton; private Button fReplaceAllButton;
private Button fCloseButton;
private IMemoryRenderingSite fMemoryView; private IMemoryRenderingSite fMemoryView;
@ -290,7 +289,7 @@ public class FindReplaceDialog extends SelectionDialog
} }
}); });
fCloseButton = createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("FindReplaceDialog.Close"), false); //$NON-NLS-1$ createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("FindReplaceDialog.Close"), false); //$NON-NLS-1$
((GridLayout) parent.getLayout()).numColumns = 2; ((GridLayout) parent.getLayout()).numColumns = 2;
@ -528,7 +527,7 @@ public class FindReplaceDialog extends SelectionDialog
*/ */
protected Control createDialogArea(Composite parent) { protected Control createDialogArea(Composite parent) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, MemorySearchPlugin.getUniqueIdentifier() + ".MemorySearchDialog_context"); //$NON-NLS-1$ PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, MemorySearchPlugin.getUniqueIdentifier() + ".FindReplaceDialog_context"); //$NON-NLS-1$
Composite composite = new Composite(parent, SWT.NONE); Composite composite = new Composite(parent, SWT.NONE);
FormLayout formLayout = new FormLayout(); FormLayout formLayout = new FormLayout();
formLayout.spacing = 5; formLayout.spacing = 5;

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>

View file

@ -1,7 +0,0 @@
#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

@ -11,6 +11,6 @@ Require-Bundle: org.eclipse.debug.core,
org.eclipse.swt, org.eclipse.swt,
org.eclipse.jface, org.eclipse.jface,
org.eclipse.ui org.eclipse.ui
Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin Bundle-Activator: org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin

View file

@ -47,6 +47,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.SelectionDialog; import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.progress.UIJob;
@SuppressWarnings("restriction")
public class ImportMemoryDialog extends SelectionDialog public class ImportMemoryDialog extends SelectionDialog
{ {
@ -179,7 +180,7 @@ public class ImportMemoryDialog extends SelectionDialog
data.left = new FormAttachment(textLabel); data.left = new FormAttachment(textLabel);
fFormatCombo.setLayoutData(data); fFormatCombo.setLayoutData(data);
Vector importers = new Vector(); Vector<Object> importers = new Vector<Object>();
IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = IExtensionPoint extensionPoint =
@ -194,7 +195,7 @@ public class ImportMemoryDialog extends SelectionDialog
{ {
try try
{ {
importers.addElement((IMemoryImporter) element.createExecutableExtension("class")); importers.addElement(element.createExecutableExtension("class"));
} }
catch(Exception e) { catch(Exception e) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -364,94 +365,98 @@ public class PlainTextExporter implements IMemoryExporter {
public void exportMemory() { public void exportMemory() {
Job job = new Job("Memory Export to Plain Text File"){ //$NON-NLS-1$ Job job = new Job("Memory Export to Plain Text File"){ //$NON-NLS-1$
public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) {
try 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)
{ {
// FIXME 4 byte default factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
BigInteger CELLSIZE = BigInteger.valueOf(4); monitor.beginTask("Transferring Data", jobs.intValue());
BigInteger COLUMNS = BigInteger.valueOf(5); // FIXME 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);
BigInteger DATA_PER_LINE = CELLSIZE.multiply(COLUMNS); monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16)));
BigInteger transferAddress = fStartAddress; StringBuffer buf = new StringBuffer();
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); // String transferAddressString = transferAddress.toString(16);
// future option // future option
// for(int i = 0; i < 8 - transferAddressString.length(); i++) // for(int i = 0; i < 8 - transferAddressString.length(); i++)
// buf.append("0"); // buf.append("0");
// buf.append(transferAddressString); // buf.append(transferAddressString);
// buf.append(" "); // TODO tab? // buf.append(" "); // TODO tab?
// data // data
for(int i = 0; i < length.divide(CELLSIZE).intValue(); i++) 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++)
{ {
if(i != 0) String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
buf.append(" "); if(bString.length() == 1)
MemoryByte bytes[] = ((IMemoryBlockExtension) fMemoryBlock).getBytesFromAddress( buf.append("0");
transferAddress.add(CELLSIZE.multiply(BigInteger.valueOf(i))), buf.append(bString);
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(buf.toString().toUpperCase());
writer.write("\n"); writer.write("\n");
transferAddress = transferAddress.add(length); transferAddress = transferAddress.add(length);
jobCount = jobCount.add(BigInteger.ONE); jobCount = jobCount.add(BigInteger.ONE);
if(jobCount.compareTo(factor) == 0) if(jobCount.compareTo(factor) == 0)
{ {
jobCount = BigInteger.ZERO; jobCount = BigInteger.ZERO;
monitor.worked(1); monitor.worked(1);
} }
}
writer.close();
monitor.done();
} }
catch(Exception e)
{ writer.close();
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), monitor.done();
DebugException.INTERNAL_ERROR, "Failure", e)); } catch (IOException ex) {
}
}
catch(Exception e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); DebugException.REQUEST_FAILED, "Could not write to file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could read from target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could read from target.", ex);
} catch (Exception ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", ex);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -276,82 +277,92 @@ public class PlainTextImporter implements IMemoryImporter {
Job job = new Job("Memory Import from Plain Text File"){ //$NON-NLS-1$ Job job = new Job("Memory Import from Plain Text File"){ //$NON-NLS-1$
public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) {
try 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)
{ {
BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH); factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
BigInteger scrollToAddress = null; monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fInputFile))); BigInteger recordAddress = fStartAddress;
String line = reader.readLine();
BigInteger jobs = BigInteger.valueOf(fInputFile.length()); int lineNo = 1; // line error reporting
BigInteger factor = BigInteger.ONE; while(line != null && !monitor.isCanceled())
if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) {
StringTokenizer st = new StringTokenizer(line, " ");
int bytesRead = 0;
while(st.hasMoreElements())
{ {
factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF)); String valueString = (String) st.nextElement();
jobs = jobs.divide(factor); int position = 0;
byte data[] = new byte[valueString.length() / 2];
for(int i = 0; i < data.length; i++)
{
try {
data[i] = new BigInteger(valueString.substring(position++, position++ + 1), 16).byteValue();
} catch (NumberFormatException ex) {
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, String.format("Invalid file format. Expected integer at line %d", lineNo ), ex);
}
}
if(scrollToAddress == null)
scrollToAddress = recordAddress;
BigInteger writeAddress =
recordAddress.subtract(((IMemoryBlockExtension)fMemoryBlock).getBigBaseAddress()).add(BigInteger.valueOf(bytesRead));
memoryWriter.write(writeAddress, data);
bytesRead += data.length;
} }
monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$ recordAddress = recordAddress.add(BigInteger.valueOf(bytesRead));
BigInteger jobCount = BigInteger.ZERO; BigInteger jobCount = BigInteger.valueOf(bytesRead).divide(factor);
BigInteger recordAddress = fStartAddress; monitor.worked(jobCount.intValue());
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) line = reader.readLine();
scrollToAddress = recordAddress; lineNo++;
}
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();
}
if (!monitor.isCanceled())
memoryWriter.flush(); memoryWriter.flush();
reader.close();
monitor.done();
if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) reader.close();
fParentDialog.scrollRenderings(scrollToAddress); monitor.done();
}
catch(Exception e) if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
{ fParentDialog.scrollRenderings(scrollToAddress);
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), } catch (IOException ex) {
DebugException.INTERNAL_ERROR, "Failure", e)); MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
} DebugException.REQUEST_FAILED, "Could not read from file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex);
} catch (Exception ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex);
} }
catch(Exception e) {e.printStackTrace();}
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};
job.setUser(true); job.setUser(true);

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -377,70 +378,74 @@ public class RAWBinaryExporter implements IMemoryExporter
{ {
Job job = new Job("Memory Export to RAW Binary File"){ //$NON-NLS-1$ Job job = new Job("Memory Export to RAW Binary File"){ //$NON-NLS-1$
public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) {
try 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)
{ {
BigInteger DATA_PER_RECORD = BigInteger.valueOf(1024); factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
BigInteger transferAddress = fStartAddress; monitor.beginTask("Transferring Data", jobs.intValue());
FileOutputStream writer = new FileOutputStream(fOutputFile); 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);
BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD); monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16)));
BigInteger factor = BigInteger.ONE;
if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) // 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++)
{ {
factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF)); byteValues[byteIndex] = bytes[byteIndex].getValue();
jobs = jobs.divide(factor);
} }
monitor.beginTask("Transferring Data", jobs.intValue());
BigInteger jobCount = BigInteger.ZERO; writer.write(byteValues);
while(transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled())
transferAddress = transferAddress.add(length);
jobCount = jobCount.add(BigInteger.ONE);
if(jobCount.compareTo(factor) == 0)
{ {
BigInteger length = DATA_PER_RECORD; jobCount = BigInteger.ZERO;
if(fEndAddress.subtract(transferAddress).compareTo(length) < 0) monitor.worked(1);
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)
{ writer.close();
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), monitor.done();
DebugException.INTERNAL_ERROR, "Failure", e)); } catch (IOException ex) {
}
}
catch(Exception e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); DebugException.REQUEST_FAILED, "Could not write to file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from target.", ex);
} catch (Exception e) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", e));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", e);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -251,80 +252,79 @@ public class RAWBinaryImporter implements IMemoryImporter {
Job job = new Job("Memory Import from RAW Binary File"){ //$NON-NLS-1$ Job job = new Job("Memory Import from RAW Binary File"){ //$NON-NLS-1$
public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) {
try 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)
{ {
BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH); factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
BigInteger scrollToAddress = null; byte[] byteValues = new byte[1024];
FileInputStream reader = new FileInputStream(fInputFile); monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
BigInteger jobs = BigInteger.valueOf(fInputFile.length()); int actualByteCount = reader.read(byteValues);
BigInteger factor = BigInteger.ONE; BigInteger recordAddress = fStartAddress;
if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0)
while(actualByteCount != -1 && !monitor.isCanceled())
{
byte data[] = new byte[actualByteCount];
for(int i = 0; i < data.length; i++)
{ {
factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF)); data[i] = byteValues[i];
jobs = jobs.divide(factor);
} }
byte[] byteValues = new byte[1024]; if(scrollToAddress == null)
scrollToAddress = recordAddress;
monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$ BigInteger baseAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
baseAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
else
baseAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
BigInteger jobCount = BigInteger.ZERO; memoryWriter.write(recordAddress.subtract(baseAddress), data);
int actualByteCount = reader.read(byteValues);
BigInteger recordAddress = fStartAddress;
while(actualByteCount != -1 && !monitor.isCanceled()) BigInteger jobCount = BigInteger.valueOf(actualByteCount).divide(factor);
{ monitor.worked(jobCount.intValue());
byte data[] = new byte[actualByteCount];
for(int i = 0; i < data.length; i++)
{
data[i] = byteValues[i];
}
if(scrollToAddress == null) recordAddress.add(BigInteger.valueOf(actualByteCount));
scrollToAddress = recordAddress; actualByteCount = reader.read(byteValues);
}
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);
}
if (!monitor.isCanceled())
memoryWriter.flush(); memoryWriter.flush();
reader.close();
monitor.done();
if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) reader.close();
fParentDialog.scrollRenderings(scrollToAddress); monitor.done();
}
catch(Exception e) if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
{ fParentDialog.scrollRenderings(scrollToAddress);
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), } catch (IOException ex) {
DebugException.INTERNAL_ERROR, "Failure", e));
}
}
catch(Exception e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); DebugException.REQUEST_FAILED, "Could not read from file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex);
} catch (Exception ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -379,110 +380,114 @@ public class SRecordExporter implements IMemoryExporter
{ {
Job job = new Job("Memory Export to S-Record File"){ //$NON-NLS-1$ Job job = new Job("Memory Export to S-Record File"){ //$NON-NLS-1$
public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) {
try 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)
{ {
// FIXME 4 byte default factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
BigInteger DATA_PER_RECORD = BigInteger.valueOf(16); monitor.beginTask("Transferring Data", jobs.intValue());
BigInteger transferAddress = fStartAddress; 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);
FileWriter writer = new FileWriter(fOutputFile); monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16)));
BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD); writer.write("S3"); // FIXME 4 byte address
BigInteger factor = BigInteger.ONE;
if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) 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++)
{ {
factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF)); String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
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) if(bString.length() == 1)
buf.append("0"); buf.append("0");
buf.append(bString); buf.append(bString);
}
writer.write(buf.toString().toUpperCase()); /*
writer.write("\n"); * 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;
transferAddress = transferAddress.add(length); for(int i = 0; i < buf.length(); i+=2)
{
BigInteger value = new BigInteger(buf.substring(i, i+2), 16);
checksum += value.byteValue();
}
jobCount = jobCount.add(BigInteger.ONE); String bString = BigInteger.valueOf(0xFF - checksum).and(BigInteger.valueOf(0xFF)).toString(16);
if(jobCount.compareTo(factor) == 0) if(bString.length() == 1)
{ buf.append("0");
jobCount = BigInteger.ZERO; buf.append(bString);
monitor.worked(1);
}
}
writer.close(); writer.write(buf.toString().toUpperCase());
monitor.done(); writer.write("\n");
transferAddress = transferAddress.add(length);
jobCount = jobCount.add(BigInteger.ONE);
if(jobCount.compareTo(factor) == 0)
{
jobCount = BigInteger.ZERO;
monitor.worked(1);
}
} }
catch(Exception e)
{ writer.close();
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), monitor.done();
DebugException.INTERNAL_ERROR, "Failure", e)); } catch (IOException ex) {
}
}
catch(Exception e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); DebugException.REQUEST_FAILED, "Could not write to file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from target.", ex);
} catch (Exception ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure exporting memory", ex);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.ui.memory.transport;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Properties; import java.util.Properties;
@ -302,125 +303,150 @@ public class SRecordImporter implements IMemoryImporter {
try 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)
{ {
BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH); factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF));
jobs = jobs.divide(factor);
}
// FIXME 4 byte default monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$
final int CHECKSUM_LENGTH = 1; String line = reader.readLine();
int lineNo = 1; // line error reporting
BigInteger scrollToAddress = null; while(line != null && !monitor.isCanceled())
{
BigInteger offset = null; String recordType = line.substring(0, 2);
if(!fProperties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "false").equals("true")) int recordCount = 0;
offset = BigInteger.ZERO; try {
recordCount = Integer.parseInt(line.substring(2, 4), 16);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fInputFile))); } catch (NumberFormatException ex) {
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
BigInteger jobs = BigInteger.valueOf(fInputFile.length()); DebugException.REQUEST_FAILED, String.format("Invalid file format. Invalid line length at line %d", lineNo ), ex);
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$ int bytesRead = 4 + recordCount;
int position = 4;
int addressSize = 0;
BigInteger jobCount = BigInteger.ZERO; BigInteger recordAddress = null;
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;
if("S3".equals(recordType)) //$NON-NLS-1$ else if("S1".equals(recordType)) //$NON-NLS-1$
addressSize = 4; addressSize = 2;
else if("S1".equals(recordType)) //$NON-NLS-1$ else if("S2".equals(recordType)) //$NON-NLS-1$
addressSize = 2; addressSize = 3;
else if("S2".equals(recordType)) //$NON-NLS-1$
addressSize = 3;
try {
recordAddress = new BigInteger(line.substring(position, position + addressSize * 2), 16); recordAddress = new BigInteger(line.substring(position, position + addressSize * 2), 16);
recordCount -= addressSize; } catch (NumberFormatException ex) {
position += addressSize * 2; return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, String.format("Invalid file format. Invalid address at line %d", lineNo ), ex);
}
recordCount -= addressSize;
position += addressSize * 2;
if(offset == null) if(offset == null)
offset = fStartAddress.subtract(recordAddress); offset = fStartAddress.subtract(recordAddress);
recordAddress = recordAddress.add(offset); recordAddress = recordAddress.add(offset);
byte data[] = new byte[recordCount - CHECKSUM_LENGTH]; byte data[] = new byte[recordCount - CHECKSUM_LENGTH];
for(int i = 0; i < data.length; i++) for(int i = 0; i < data.length; i++)
{ {
try {
data[i] = new BigInteger(line.substring(position++, position++ + 1), 16).byteValue(); data[i] = new BigInteger(line.substring(position++, position++ + 1), 16).byteValue();
} catch (NumberFormatException ex) {
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, String.format("Invalid file format. Invalid data at line %d", lineNo ), ex);
} }
}
/* /*
* The least significant byte of the one's complement of the sum of the values * 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, * represented by the pairs of characters making up the records length, address,
* and the code/data fields. * and the code/data fields.
*/ */
StringBuffer buf = new StringBuffer(line.substring(2)); StringBuffer buf = new StringBuffer(line.substring(2));
byte checksum = 0; byte checksum = 0;
for(int i = 0; i < buf.length(); i+=2) for(int i = 0; i < buf.length(); i+=2)
{ {
BigInteger value = new BigInteger(buf.substring(i, i+2), 16); BigInteger value = null;
checksum += value.byteValue(); try {
value = new BigInteger(buf.substring(i, i+2), 16);
} catch (NumberFormatException ex) {
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, String.format("Invalid file format. Invalid checksum format at line %d", lineNo ), ex);
} }
checksum += value.byteValue();
}
/* /*
* Since we included the checksum in the checksum calculation the checksum * 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 * ( if correct ) will always be 0xFF which is -1 using the signed byte size
* calculation here. * calculation here.
*/ */
if ( checksum != (byte) -1 ) { if ( checksum != (byte) -1 ) {
reader.close(); reader.close();
monitor.done(); monitor.done();
return new Status( IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), "Checksum failure of line = " + line); //$NON-NLS-1$ return new Status( IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), "Checksum failure of line = " + line); //$NON-NLS-1$
} }
if(scrollToAddress == null) if(scrollToAddress == null)
scrollToAddress = recordAddress; scrollToAddress = recordAddress;
// FIXME error on incorrect checksum // FIXME error on incorrect checksum
memoryWriter.write(recordAddress.subtract(((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress()), data); memoryWriter.write(recordAddress.subtract(((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress()), data);
jobCount = jobCount.add(BigInteger.valueOf(bytesRead)); BigInteger jobCount = BigInteger.valueOf(bytesRead).divide(factor);
while(jobCount.compareTo(factor) >= 0) monitor.worked(jobCount.intValue());
{
jobCount = jobCount.subtract(factor);
monitor.worked(1);
}
line = reader.readLine(); line = reader.readLine();
} lineNo++;
}
if (!monitor.isCanceled())
memoryWriter.flush(); memoryWriter.flush();
reader.close();
monitor.done();
if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) reader.close();
fParentDialog.scrollRenderings(scrollToAddress); monitor.done();
}
catch(Exception e) if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true"))
{ fParentDialog.scrollRenderings(scrollToAddress);
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), } catch (IOException ex) {
DebugException.INTERNAL_ERROR, "Failure", e));
}
}
catch(Exception e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); DebugException.REQUEST_FAILED, "Could not read from file.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not read from file.", ex);
} catch (DebugException ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.REQUEST_FAILED, "Could not write to target.", ex);
} catch (Exception ex) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex));
return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure importing from file", ex);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}}; }};