From cab5fc1752f9b0578e250a194e312a59b7252802 Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Mon, 13 Apr 2020 17:16:48 +0100 Subject: [PATCH] Bug 390897: Data buffering for SRecord export Change-Id: I52cb28cd7fbbf19a9d2bc39754e0ea6fd8582aa3 --- .../META-INF/MANIFEST.MF | 2 +- .../ui/memory/transport/SRecordExporter.java | 115 ++++++++++-------- 2 files changed, 66 insertions(+), 51 deletions(-) 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 50f2afd7066..8d3a4901987 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 @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.transport;singleton:=true -Bundle-Version: 2.1.100.qualifier +Bundle-Version: 2.1.200.qualifier Bundle-Localization: plugin Bundle-Vendor: %providerName Require-Bundle: org.eclipse.debug.core, 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 0ec3254f294..e71c4edb2e6 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2016 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2020 Wind River Systems, Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * Ted R Williams (Wind River Systems, Inc.) - initial implementation + * John Dallaway - Enhanced data buffering for performance (bug 390897) *******************************************************************************/ package org.eclipse.cdt.debug.ui.memory.transport; @@ -497,6 +498,7 @@ public class SRecordExporter implements IMemoryExporter { // FIXME 4 byte default BigInteger DATA_PER_RECORD = BigInteger.valueOf(16); + BigInteger DATA_PER_TRANSFER = BigInteger.valueOf(4096).multiply(DATA_PER_RECORD); BigInteger transferAddress = fStartAddress; @@ -513,69 +515,82 @@ public class SRecordExporter implements IMemoryExporter { BigInteger jobCount = BigInteger.ZERO; while (transferAddress.compareTo(fEndAddress) < 0 && !monitor.isCanceled()) { - BigInteger length = DATA_PER_RECORD; + BigInteger length = DATA_PER_TRANSFER; if (fEndAddress.subtract(transferAddress).compareTo(length) < 0) length = fEndAddress.subtract(transferAddress); monitor.subTask(String.format(Messages.getString("Exporter.Progress"), length.toString(10), //$NON-NLS-1$ transferAddress.toString(16))); - writer.write("S3"); // FIXME 4 byte address //$NON-NLS-1$ - - StringBuilder buf = new StringBuilder(); - - 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"); //$NON-NLS-1$ - buf.append(lengthString); - for (int i = 0; i < 8 - transferAddressString.length(); i++) - buf.append("0"); //$NON-NLS-1$ - 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); + + BigInteger sRecordAddress = transferAddress; + BigInteger sRecordEndAddress = transferAddress.add(length); + while (sRecordAddress.compareTo(sRecordEndAddress) < 0 && !monitor.isCanceled()) { + BigInteger sRecordDataLength = DATA_PER_RECORD; + if (sRecordEndAddress.subtract(sRecordAddress).compareTo(sRecordDataLength) < 0) { + sRecordDataLength = fEndAddress.subtract(sRecordAddress); + } + + writer.write("S3"); // FIXME 4 byte address //$NON-NLS-1$ + + StringBuilder buf = new StringBuilder(); + + BigInteger sRecordLength = BigInteger.valueOf(4); // address size + sRecordLength = sRecordLength.add(sRecordDataLength); + sRecordLength = sRecordLength.add(BigInteger.ONE); // checksum + + String transferAddressString = sRecordAddress.toString(16); + + String lengthString = sRecordLength.toString(16); + if (lengthString.length() == 1) + buf.append("0"); //$NON-NLS-1$ + buf.append(lengthString); + for (int i = 0; i < 8 - transferAddressString.length(); i++) + buf.append("0"); //$NON-NLS-1$ + buf.append(transferAddressString); + + final int byteOffset = sRecordAddress.subtract(transferAddress).intValue(); + final int byteLength = byteOffset + sRecordDataLength.intValue(); + for (int byteIndex = byteOffset; byteIndex < byteLength; byteIndex++) { + String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16); + if (bString.length() == 1) + buf.append("0"); //$NON-NLS-1$ + buf.append(bString); + } + + /* + * The least significant byte of the one's complement of the sum of the values + * represented by the pairs of characters making up the records length, address, + * and the code/data fields. + */ + byte checksum = 0; + + for (int i = 0; i < buf.length(); i += 2) { + BigInteger value = new BigInteger(buf.substring(i, i + 2), 16); + checksum += value.byteValue(); + } + + String bString = BigInteger.valueOf(0xFF - checksum).and(BigInteger.valueOf(0xFF)) + .toString(16); if (bString.length() == 1) buf.append("0"); //$NON-NLS-1$ buf.append(bString); + + writer.write(buf.toString().toUpperCase()); + writer.write("\n"); //$NON-NLS-1$ + + sRecordAddress = sRecordAddress.add(sRecordDataLength); + + jobCount = jobCount.add(BigInteger.ONE); + if (jobCount.compareTo(factor) == 0) { + jobCount = BigInteger.ZERO; + monitor.worked(1); + } } - /* - * 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"); //$NON-NLS-1$ - buf.append(bString); - - writer.write(buf.toString().toUpperCase()); - writer.write("\n"); //$NON-NLS-1$ - transferAddress = transferAddress.add(length); - - jobCount = jobCount.add(BigInteger.ONE); - if (jobCount.compareTo(factor) == 0) { - jobCount = BigInteger.ZERO; - monitor.worked(1); - } } writer.close();