From 0d66821cc13cd4922df34ace9e60a2aaeb01a17c Mon Sep 17 00:00:00 2001 From: Randy Rohrbach Date: Sun, 18 Oct 2009 04:53:48 +0000 Subject: [PATCH] Bugzilla defects 256775 283586 287540 290710 292059 292120 292293 --- dsf/org.eclipse.cdt.dsf.ui/plugin.xml | 5 +- .../memory/memorybrowser/MemoryBrowser.java | 171 ++++++++---- .../plugin.xml | 4 + .../ui/memory/search/FindReplaceDialog.java | 5 +- .../.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 2 +- .../memory/transport/ImportMemoryDialog.java | 5 +- .../memory/transport/PlainTextExporter.java | 155 +++++------ .../memory/transport/PlainTextImporter.java | 137 +++++----- .../memory/transport/RAWBinaryExporter.java | 113 ++++---- .../memory/transport/RAWBinaryImporter.java | 134 +++++----- .../ui/memory/transport/SRecordExporter.java | 189 +++++++------- .../ui/memory/transport/SRecordImporter.java | 246 ++++++++++-------- 14 files changed, 643 insertions(+), 532 deletions(-) delete mode 100644 memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs diff --git a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml index dfdf23d7a91..55a5523d7ac 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml +++ b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml @@ -515,8 +515,8 @@ - - + + diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java index d9e3eaf3d87..21423835b56 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java @@ -70,8 +70,8 @@ import org.eclipse.swt.custom.CTabFolder2Adapter; import org.eclipse.swt.custom.CTabFolderEvent; import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; 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 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 fCurrentContainers = new ArrayList(); - 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_RETRIEVAL = "RETRIEVAL"; //$NON-NLS-1$ - private final static String KEY_CONTAINER = "CONTAINER"; //$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_MEMORY_BLOCK = "MEMORY"; //$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() { } @@ -175,11 +177,10 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL } }); - fGotoAddressBar.getExpressionWidget().addKeyListener(new KeyListener(){ - public void keyPressed(KeyEvent e) {} - public void keyReleased(KeyEvent e) { - if(e.keyCode == SWT.CR) - performGo(false); + fGotoAddressBar.getExpressionWidget().addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) {} + public void widgetDefaultSelected(SelectionEvent e) { + performGo(false); } }); @@ -270,9 +271,12 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL public void launchChanged(ILaunch launch) {} public void launchRemoved(ILaunch launch) { - IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) launch.getAdapter(IMemoryBlockRetrieval.class)); - if(retrieval != null) - releaseTabFolder(retrieval); + // For CDT launch is not adaptable to memory rendering, but the debug targets do. + for (IDebugTarget target : launch.getDebugTargets()) { + IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) target.getAdapter(IMemoryBlockRetrieval.class)); + if(retrieval != null) + releaseTabFolder(retrieval); + } } public IMemoryRenderingContainer getContainer(String id) { @@ -323,10 +327,8 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL { public void run() { - IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension) retrieval; try { - IMemoryBlockExtension newBlock = retrievalExtension.getExtendedMemoryBlock(expression, context); - BigInteger newBase = newBlock.getBigBaseAddress(); + BigInteger newBase = getExpressionAddress(retrieval, expression, context); if(((IMemoryBlockExtension) rendering.getMemoryBlock()).supportBaseAddressModification()) ((IMemoryBlockExtension) rendering.getMemoryBlock()).setBaseAddress(newBase); rendering.goToAddress(newBase); @@ -366,7 +368,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL 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(); 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.setBorderVisible(true); + // listener to dispose rendering resources for each closed tab folder.addCTabFolder2Listener(new CTabFolder2Adapter() { public void close(CTabFolderEvent event) { - event.doit = false; + event.doit = true; CTabItem item = (CTabItem) event.item; - IMemoryRenderingContainer container = (IMemoryRenderingContainer) item.getData(KEY_CONTAINER); - fCurrentContainers.remove( container ); + disposeTab(item); + } + }); + + // 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; } + /** + * 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) { int swtStyle = SWT.CLOSE; CTabItem tab = new CTabItem(tabFolder, swtStyle, index); @@ -496,42 +532,36 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL if(context instanceof IAdaptable) { IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) ((IAdaptable) context).getAdapter(IMemoryBlockRetrieval.class)); + if(retrieval != null) { fGotoAddressBarControl.setVisible(true); - if(getTabFolder(retrieval) != null) + CTabFolder tabFolder = getTabFolder(retrieval); + if(tabFolder != null) { - fStackLayout.topControl = getTabFolder(retrieval); + fStackLayout.topControl = tabFolder; } else { - CTabFolder newFolder = this.createTabFolder(fRenderingsComposite); - newFolder.addCTabFolder2Listener(new CTabFolder2Adapter() { - 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() + tabFolder = this.createTabFolder(fRenderingsComposite); + tabFolder.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} - public void widgetSelected(SelectionEvent e) { getSite().getSelectionProvider().setSelection(new StructuredSelection(((CTabItem) e.item).getData(KEY_RENDERING))); } }); - newFolder.setData(KEY_CONTEXT, context); - newFolder.setData(KEY_RETRIEVAL, retrieval); + tabFolder.setData(KEY_RETRIEVAL, retrieval); - CTabItem item = createTab(newFolder, 0); + CTabItem item = createTab(tabFolder, 0); populateTabWithRendering(item, retrieval, context); - setTabFolder(retrieval, newFolder); + setTabFolder(retrieval, tabFolder); fStackLayout.topControl = getTabFolder(retrieval); } + // update debug context to the new selection + tabFolder.setData(KEY_CONTEXT, context); } else { @@ -585,19 +615,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL }; - IMemoryBlock block = null; - 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; - } + IMemoryBlock block = createMemoryBlock(retrieval, "0", context); fCurrentContainers.add(container); rendering.init(container, block); @@ -606,6 +624,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL tab.getParent().setSelection(0); tab.setData(KEY_RENDERING, rendering); tab.setData(KEY_CONTAINER, container); + tab.setData(KEY_MEMORY_BLOCK, block); getSite().getSelectionProvider().setSelection(new StructuredSelection(tab.getData(KEY_RENDERING))); updateLabel(tab, rendering); @@ -648,12 +667,15 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IL if(folder != null) { for(CTabItem tab : folder.getItems()) { - IMemoryRenderingContainer container = (IMemoryRenderingContainer) tab.getData(KEY_CONTAINER); - fCurrentContainers.remove( container ); - tab.dispose(); + disposeTab(tab); } } fContextFolders.remove(context); + folder.dispose(); + + if (fStackLayout.topControl.equals(folder)) { + handleUnsupportedSelection(); + } } 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; } } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.search/plugin.xml b/memory/org.eclipse.cdt.debug.ui.memory.search/plugin.xml index fda90937dc5..06164320fd5 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.search/plugin.xml +++ b/memory/org.eclipse.cdt.debug.ui.memory.search/plugin.xml @@ -9,6 +9,7 @@ class="org.eclipse.cdt.debug.ui.memory.search.FindAction" enablesFor="1" id="org.eclipse.cdt.debug.ui.memory.search.FindAction" + helpContextId="FindNextAction_context" label="%action.label.0" menubarPath="additions"> @@ -20,6 +21,7 @@ class="org.eclipse.cdt.debug.ui.memory.search.FindAction" enablesFor="1" id="org.eclipse.cdt.debug.ui.memory.search.FindAction" + helpContextId="FindReplaceAction_context" label="%action.label.1" menubarPath="additions"> @@ -32,6 +34,7 @@ class="org.eclipse.cdt.debug.ui.memory.search.FindAction" enablesFor="1" id="org.eclipse.cdt.debug.ui.memory.search.FindAction" + helpContextId="FindNextAction_context" label="%action.label.2" menubarPath="additions"> @@ -43,6 +46,7 @@ class="org.eclipse.cdt.debug.ui.memory.search.FindAction" enablesFor="1" id="org.eclipse.cdt.debug.ui.memory.search.FindAction" + helpContextId="FindReplaceAction_context" label="%action.label.3" menubarPath="additions"> diff --git a/memory/org.eclipse.cdt.debug.ui.memory.search/src/org/eclipse/cdt/debug/ui/memory/search/FindReplaceDialog.java b/memory/org.eclipse.cdt.debug.ui.memory.search/src/org/eclipse/cdt/debug/ui/memory/search/FindReplaceDialog.java index d1aa20f2b9d..23e38d66898 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.search/src/org/eclipse/cdt/debug/ui/memory/search/FindReplaceDialog.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.search/src/org/eclipse/cdt/debug/ui/memory/search/FindReplaceDialog.java @@ -75,7 +75,6 @@ public class FindReplaceDialog extends SelectionDialog private Button fReplaceButton; private Button fReplaceFindButton; private Button fReplaceAllButton; - private Button fCloseButton; 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; @@ -528,7 +527,7 @@ public class FindReplaceDialog extends SelectionDialog */ 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); FormLayout formLayout = new FormLayout(); formLayout.spacing = 5; diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath b/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath index 2fbb7a23e12..64c5e31b7a2 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/.classpath @@ -1,6 +1,6 @@ - + diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs b/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b51d4342d8d..00000000000 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -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 diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF b/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF index 9585aef8c0c..40436013918 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/META-INF/MANIFEST.MF @@ -11,6 +11,6 @@ Require-Bundle: org.eclipse.debug.core, org.eclipse.swt, org.eclipse.jface, org.eclipse.ui -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java index ee47c97f95b..7ad1306e5f1 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/ImportMemoryDialog.java @@ -47,6 +47,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.SelectionDialog; import org.eclipse.ui.progress.UIJob; +@SuppressWarnings("restriction") public class ImportMemoryDialog extends SelectionDialog { @@ -179,7 +180,7 @@ public class ImportMemoryDialog extends SelectionDialog data.left = new FormAttachment(textLabel); fFormatCombo.setLayoutData(data); - Vector importers = new Vector(); + Vector importers = new Vector(); IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = @@ -194,7 +195,7 @@ public class ImportMemoryDialog extends SelectionDialog { try { - importers.addElement((IMemoryImporter) element.createExecutableExtension("class")); + importers.addElement(element.createExecutableExtension("class")); } catch(Exception e) { MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java index 837f82810bc..d376d9821ca 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextExporter.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.math.BigInteger; import java.util.Properties; @@ -364,94 +365,98 @@ public class PlainTextExporter implements IMemoryExporter { 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 + { + // 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); + } - BigInteger CELLSIZE = BigInteger.valueOf(4); + 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); - BigInteger COLUMNS = BigInteger.valueOf(5); // FIXME + monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16))); - BigInteger DATA_PER_LINE = CELLSIZE.multiply(COLUMNS); + StringBuffer buf = new StringBuffer(); - 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 + + // 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(); + // 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); + } } - catch(Exception e) - { - MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), - DebugException.INTERNAL_ERROR, "Failure", e)); - } - } - catch(Exception e) - { + + writer.close(); + monitor.done(); + } catch (IOException ex) { 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; }}; diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java index 02403238339..59bc5968c83 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/PlainTextImporter.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; 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$ public IStatus run(IProgressMonitor monitor) { - try - { - try - { - BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH); + { + 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); + } - 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) + monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$ + + BigInteger recordAddress = fStartAddress; + String line = reader.readLine(); + int lineNo = 1; // line error reporting + while(line != null && !monitor.isCanceled()) + { + StringTokenizer st = new StringTokenizer(line, " "); + int bytesRead = 0; + while(st.hasMoreElements()) { - 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++) { - String valueString = (String) st.nextElement(); - 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; } - recordAddress = recordAddress.add(BigInteger.valueOf(bytesRead)); + if(scrollToAddress == null) + scrollToAddress = recordAddress; - jobCount = jobCount.add(BigInteger.valueOf(bytesRead)); - while(jobCount.compareTo(factor) >= 0) - { - jobCount = jobCount.subtract(factor); - monitor.worked(1); - } + BigInteger writeAddress = + + recordAddress.subtract(((IMemoryBlockExtension)fMemoryBlock).getBigBaseAddress()).add(BigInteger.valueOf(bytesRead)); - line = reader.readLine(); - } + memoryWriter.write(writeAddress, data); + + bytesRead += data.length; + } + recordAddress = recordAddress.add(BigInteger.valueOf(bytesRead)); + + BigInteger jobCount = BigInteger.valueOf(bytesRead).divide(factor); + monitor.worked(jobCount.intValue()); + + line = reader.readLine(); + lineNo++; + } + + if (!monitor.isCanceled()) 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)); - } + + reader.close(); + monitor.done(); + + if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) + fParentDialog.scrollRenderings(scrollToAddress); + } catch (IOException ex) { + 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; }}; job.setUser(true); diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java index 8000ff24075..4b8ec8c532a 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryExporter.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.math.BigInteger; 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$ public IStatus run(IProgressMonitor monitor) { - try - { - try - { - BigInteger DATA_PER_RECORD = BigInteger.valueOf(1024); + { + 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); + } - BigInteger transferAddress = fStartAddress; + 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); - FileOutputStream writer = new FileOutputStream(fOutputFile); + monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16))); + + // data + byte[] byteValues = new byte[length.intValue()]; - BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD); - BigInteger factor = BigInteger.ONE; - if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) + 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)); - jobs = jobs.divide(factor); + byteValues[byteIndex] = bytes[byteIndex].getValue(); } - - monitor.beginTask("Transferring Data", jobs.intValue()); - BigInteger jobCount = BigInteger.ZERO; - while(transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled()) + + writer.write(byteValues); + + transferAddress = transferAddress.add(length); + + jobCount = jobCount.add(BigInteger.ONE); + if(jobCount.compareTo(factor) == 0) { - 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(); + jobCount = BigInteger.ZERO; + monitor.worked(1); + } } - catch(Exception e) - { - MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), - DebugException.INTERNAL_ERROR, "Failure", e)); - } - } - catch(Exception e) - { + + writer.close(); + monitor.done(); + } catch (IOException ex) { 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; }}; diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java index 2026e546fa4..0b58dcbcf1e 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/RAWBinaryImporter.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.math.BigInteger; 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$ 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) + { + 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$ + + 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++) { - factor = jobs.divide(BigInteger.valueOf(0x7FFFFFFF)); - jobs = jobs.divide(factor); + data[i] = byteValues[i]; } - - 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); - } + 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); + + BigInteger jobCount = BigInteger.valueOf(actualByteCount).divide(factor); + monitor.worked(jobCount.intValue()); + + recordAddress.add(BigInteger.valueOf(actualByteCount)); + actualByteCount = reader.read(byteValues); + } + + if (!monitor.isCanceled()) 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) - { + + reader.close(); + monitor.done(); + + if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) + fParentDialog.scrollRenderings(scrollToAddress); + } catch (IOException ex) { 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; }}; diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java index 83f70cf5c1d..2c818db1d67 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordExporter.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.math.BigInteger; 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$ public IStatus run(IProgressMonitor monitor) { - try - { - try - { - // FIXME 4 byte default + { + // 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); + } - BigInteger DATA_PER_RECORD = BigInteger.valueOf(16); + 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); - BigInteger transferAddress = fStartAddress; + monitor.subTask(String.format("Transfering %s bytes at address 0x%s", length.toString(10), transferAddress.toString(16))); + + writer.write("S3"); // FIXME 4 byte address - FileWriter writer = new FileWriter(fOutputFile); + StringBuffer buf = new StringBuffer(); - BigInteger jobs = fEndAddress.subtract(transferAddress).divide(DATA_PER_RECORD); - BigInteger factor = BigInteger.ONE; - if(jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) + 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)); - 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); + 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(); + /* + * 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); + } } - catch(Exception e) - { - MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), - DebugException.INTERNAL_ERROR, "Failure", e)); - } - } - catch(Exception e) - { + + writer.close(); + monitor.done(); + } catch (IOException ex) { 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; }}; diff --git a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java index 550db13bb47..41c62197835 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.transport/src/org/eclipse/cdt/debug/ui/memory/transport/SRecordImporter.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.ui.memory.transport; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.Properties; @@ -301,126 +302,151 @@ public class SRecordImporter implements IMemoryImporter { public IStatus run(IProgressMonitor monitor) { try - { - try - { - BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH); + { + 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); + } - // 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$ + + String line = reader.readLine(); + int lineNo = 1; // line error reporting + while(line != null && !monitor.isCanceled()) + { + String recordType = line.substring(0, 2); + int recordCount = 0; + try { + recordCount = Integer.parseInt(line.substring(2, 4), 16); + } catch (NumberFormatException ex) { + return new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), + DebugException.REQUEST_FAILED, String.format("Invalid file format. Invalid line length at line %d", lineNo ), ex); } - - monitor.beginTask("Transferring Data", jobs.intValue()); //$NON-NLS-1$ + + int bytesRead = 4 + recordCount; + int position = 4; + int addressSize = 0; - 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; - + 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; + + try { 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++) - { + } catch (NumberFormatException ex) { + 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) + offset = fStartAddress.subtract(recordAddress); + + recordAddress = recordAddress.add(offset); + + byte data[] = new byte[recordCount - CHECKSUM_LENGTH]; + for(int i = 0; i < data.length; i++) + { + try { 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 - * 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(); - } + /* + * 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 = null; + 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 + * ( 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); + + BigInteger jobCount = BigInteger.valueOf(bytesRead).divide(factor); + monitor.worked(jobCount.intValue()); + + line = reader.readLine(); + lineNo++; + } + + if (!monitor.isCanceled()) 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) - { + + reader.close(); + monitor.done(); + + if(fProperties.getProperty(TRANSFER_SCROLL_TO_START, "false").equals("true")) + fParentDialog.scrollRenderings(scrollToAddress); + } catch (IOException ex) { 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; }};