mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 21:35:40 +02:00
Bug 562164 - Add JUnit tests for IMemoryExporter implementations
Added "number of units to retrieve" parameter to ReadMemory#from Fixed result compare for text-based formats Returning back 64KiB DATA_PER_TRANSFER optimization Reworked FileExport from "O extends AutoCloseable" Renamed ReadMemory to IReadMemory Change-Id: Id7eb51015884d5dbffa5e91e9601f5e6ddb52d90 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
e1f6300001
commit
d374b71c94
14 changed files with 111 additions and 85 deletions
|
@ -16,32 +16,56 @@ package org.eclipse.cdt.debug.core.memory.tests;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ReadMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.IReadMemory;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.WriteMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.WriteMemory;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple emulator of memory block to control the memory transport without real device
|
* Simple emulator of memory block to control the memory transport without real device
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
final class EmulateMemory implements WriteMemory, ReadMemory {
|
final class EmulateMemory implements WriteMemory, IReadMemory {
|
||||||
|
|
||||||
|
private final BigInteger addressable;
|
||||||
private final BigInteger base;
|
private final BigInteger base;
|
||||||
|
//FIXME: needs improvements, assumes identical pattern during write and read
|
||||||
private final Map<BigInteger, byte[]> storage;
|
private final Map<BigInteger, byte[]> storage;
|
||||||
|
|
||||||
EmulateMemory(BigInteger base) {
|
EmulateMemory(BigInteger addressable, BigInteger base) {
|
||||||
storage = new LinkedHashMap<>();
|
this.addressable = addressable;
|
||||||
this.base = base;
|
this.base = base;
|
||||||
|
this.storage = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] from(BigInteger offset) throws DebugException {
|
public MemoryByte[] from(BigInteger offset, long units) throws DebugException {
|
||||||
return Optional.ofNullable(storage.get(offset)).orElseThrow(() -> failed(offset));
|
int length = (int) (units * addressable.longValue());
|
||||||
|
MemoryByte[] result = new MemoryByte[length];
|
||||||
|
int i = 0;
|
||||||
|
while (i < length) {
|
||||||
|
byte[] raw = storage.getOrDefault(offset.add(BigInteger.valueOf(i)), new byte[0]);
|
||||||
|
int obtained = raw.length;
|
||||||
|
if (obtained > 0) {
|
||||||
|
for (int j = 0; j < obtained; j++) {
|
||||||
|
result[i + j] = new MemoryByte(raw[j]);
|
||||||
|
}
|
||||||
|
i = i + obtained;
|
||||||
|
} else {
|
||||||
|
//unreachable with current test data
|
||||||
|
MemoryByte unavailable = new MemoryByte();
|
||||||
|
unavailable.setReadable(false);
|
||||||
|
for (int j = i; j < length; j++) {
|
||||||
|
result[i + j] = unavailable;
|
||||||
|
}
|
||||||
|
i = length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
|
@ -58,7 +59,7 @@ public final class PlainTextTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
||||||
EmulateMemory memory = new EmulateMemory(base);
|
EmulateMemory memory = new EmulateMemory(BigInteger.valueOf(1), base);
|
||||||
Consumer<BigInteger> scroll = new CollectScrolls();
|
Consumer<BigInteger> scroll = new CollectScrolls();
|
||||||
File input = new InputFile(name).get();
|
File input = new InputFile(name).get();
|
||||||
new PlainTextImport(input, new ImportRequest(base, start, memory), scroll)//
|
new PlainTextImport(input, new ImportRequest(base, start, memory), scroll)//
|
||||||
|
@ -66,11 +67,11 @@ public final class PlainTextTransportTest {
|
||||||
File output = new OutputFile(name).get();
|
File output = new OutputFile(name).get();
|
||||||
new PlainTextExport(output, new ExportRequest(start, end, BigInteger.ONE, memory))//
|
new PlainTextExport(output, new ExportRequest(start, end, BigInteger.ONE, memory))//
|
||||||
.run(new NullProgressMonitor());
|
.run(new NullProgressMonitor());
|
||||||
Assert.assertArrayEquals(read(input), read(output));
|
Assert.assertEquals(read(input), read(output));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] read(File file) throws IOException {
|
private List<String> read(File file) throws IOException {
|
||||||
return Files.readAllBytes(Paths.get(file.toString()));
|
return Files.readAllLines(Paths.get(file.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class RAWBinaryTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
||||||
EmulateMemory memory = new EmulateMemory(base);
|
EmulateMemory memory = new EmulateMemory(BigInteger.valueOf(1), base);
|
||||||
Consumer<BigInteger> scroll = new CollectScrolls();
|
Consumer<BigInteger> scroll = new CollectScrolls();
|
||||||
File input = new InputFile(name).get();
|
File input = new InputFile(name).get();
|
||||||
new RAWBinaryImport(input, new ImportRequest(base, start, memory), scroll)//
|
new RAWBinaryImport(input, new ImportRequest(base, start, memory), scroll)//
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
|
@ -58,7 +59,7 @@ public final class SRecordTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
private void transport(String name, BigInteger end) throws CoreException, IOException {
|
||||||
EmulateMemory memory = new EmulateMemory(base);
|
EmulateMemory memory = new EmulateMemory(BigInteger.valueOf(1), base);
|
||||||
Consumer<BigInteger> scroll = new CollectScrolls();
|
Consumer<BigInteger> scroll = new CollectScrolls();
|
||||||
File input = new InputFile(name).get();
|
File input = new InputFile(name).get();
|
||||||
File output = new OutputFile(name).get();
|
File output = new OutputFile(name).get();
|
||||||
|
@ -74,8 +75,9 @@ public final class SRecordTransportTest {
|
||||||
Assert.assertArrayEquals(read(input), read(output));
|
Assert.assertArrayEquals(read(input), read(output));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] read(File file) throws IOException {
|
private String[] read(File file) throws IOException {
|
||||||
return Files.readAllBytes(Paths.get(file.toString()));
|
List<String> lines = Files.readAllLines(Paths.get(file.toString()));
|
||||||
|
return lines.toArray(new String[lines.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@ public final class ExportRequest {
|
||||||
private final BigInteger start;
|
private final BigInteger start;
|
||||||
private final BigInteger end;
|
private final BigInteger end;
|
||||||
private final BigInteger addressable;
|
private final BigInteger addressable;
|
||||||
private final ReadMemory read;
|
private final IReadMemory read;
|
||||||
|
|
||||||
public ExportRequest(BigInteger start, BigInteger end, BigInteger addressable, ReadMemory read) {
|
public ExportRequest(BigInteger start, BigInteger end, BigInteger addressable, IReadMemory read) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.addressable = addressable;
|
this.addressable = addressable;
|
||||||
|
@ -64,7 +64,7 @@ public final class ExportRequest {
|
||||||
*
|
*
|
||||||
* @return reader
|
* @return reader
|
||||||
*/
|
*/
|
||||||
public ReadMemory read() {
|
public IReadMemory read() {
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.debug.core.memory.transport;
|
package org.eclipse.cdt.debug.core.memory.transport;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.Messages;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.Messages;
|
||||||
|
@ -32,12 +35,12 @@ import org.osgi.framework.FrameworkUtil;
|
||||||
*
|
*
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
*/
|
*/
|
||||||
public abstract class FileExport<O extends AutoCloseable> implements ICoreRunnable {
|
public abstract class FileExport implements ICoreRunnable {
|
||||||
|
|
||||||
protected final BigInteger start;
|
protected final BigInteger start;
|
||||||
protected final BigInteger end;
|
protected final BigInteger end;
|
||||||
protected final BigInteger addressable;
|
protected final BigInteger addressable;
|
||||||
protected final ReadMemory read;
|
protected final IReadMemory read;
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
|
|
||||||
|
@ -51,7 +54,7 @@ public abstract class FileExport<O extends AutoCloseable> implements ICoreRunnab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IProgressMonitor monitor) throws CoreException {
|
public void run(IProgressMonitor monitor) throws CoreException {
|
||||||
try (O writer = output(file)) {
|
try (OutputStream output = output(file)) {
|
||||||
BigInteger jobs = end.subtract(start).divide(chunkSize());
|
BigInteger jobs = end.subtract(start).divide(chunkSize());
|
||||||
BigInteger factor = BigInteger.ONE;
|
BigInteger factor = BigInteger.ONE;
|
||||||
if (jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) {
|
if (jobs.compareTo(BigInteger.valueOf(0x7FFFFFFF)) > 0) {
|
||||||
|
@ -59,7 +62,8 @@ public abstract class FileExport<O extends AutoCloseable> implements ICoreRunnab
|
||||||
jobs = jobs.divide(factor);
|
jobs = jobs.divide(factor);
|
||||||
}
|
}
|
||||||
monitor.beginTask(Messages.FileExport_task_transferring, jobs.intValue());
|
monitor.beginTask(Messages.FileExport_task_transferring, jobs.intValue());
|
||||||
transfer(writer, factor, monitor);
|
transfer(output, factor, monitor);
|
||||||
|
output.flush();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
requestFailed(Messages.FileExport_e_write_file, ex);
|
requestFailed(Messages.FileExport_e_write_file, ex);
|
||||||
} catch (DebugException ex) {
|
} catch (DebugException ex) {
|
||||||
|
@ -72,13 +76,16 @@ public abstract class FileExport<O extends AutoCloseable> implements ICoreRunnab
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the writer for the given file
|
* Creates the output stream for the given file
|
||||||
*
|
*
|
||||||
* @param file to export to
|
* @param file to export to
|
||||||
* @return writer instance
|
* @return writer instance
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected abstract O output(File file) throws IOException;
|
protected OutputStream output(File file) throws IOException {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
return new BufferedOutputStream(new FileOutputStream(file));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the data chunk to use for export
|
* Determines the data chunk to use for export
|
||||||
|
@ -87,7 +94,7 @@ public abstract class FileExport<O extends AutoCloseable> implements ICoreRunnab
|
||||||
*/
|
*/
|
||||||
protected abstract BigInteger chunkSize();
|
protected abstract BigInteger chunkSize();
|
||||||
|
|
||||||
protected abstract void transfer(O output, BigInteger factor, IProgressMonitor monitor)
|
protected abstract void transfer(OutputStream output, BigInteger factor, IProgressMonitor monitor)
|
||||||
throws IOException, DebugException;
|
throws IOException, DebugException;
|
||||||
|
|
||||||
protected String transferring(BigInteger length, BigInteger address) {
|
protected String transferring(BigInteger length, BigInteger address) {
|
||||||
|
|
|
@ -16,21 +16,27 @@ package org.eclipse.cdt.debug.core.memory.transport;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an array of bytes using the given offset
|
* Reads an array of bytes using the given offset
|
||||||
*
|
*
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
*/
|
*/
|
||||||
public interface ReadMemory {
|
public interface IReadMemory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an array of bytes from a memory starting from the given offset.
|
* Reads an array of bytes from a memory starting from the given offset. If requested to retrieve data beyond the memory
|
||||||
|
* boundaries, implementations should return memory bytes with the <code>READABLE</code> bit turned off for each byte outside the
|
||||||
|
* of the accessible range. An exception should not be thrown in this case.
|
||||||
*
|
*
|
||||||
* @param offset
|
* @param offset zero based offset at which to start retrieving bytes in terms of addressable units
|
||||||
* @return the obtained data
|
* @param units the number of addressable units to retrieve
|
||||||
* @throws DebugException
|
* @return the obtained data, {@link MemoryByte#isReadable()} needs to be checked
|
||||||
|
* @throws DebugException if unable to retrieve the specified bytes due to a failure communicating with the target
|
||||||
|
*
|
||||||
|
* @see {@link MemoryByte}
|
||||||
*/
|
*/
|
||||||
byte[] from(BigInteger offset) throws DebugException;
|
MemoryByte[] from(BigInteger offset, long units) throws DebugException;
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,27 +15,22 @@
|
||||||
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
|
|
||||||
public final class PlainTextExport extends FileExport<FileWriter> {
|
public final class PlainTextExport extends FileExport {
|
||||||
|
|
||||||
public PlainTextExport(File output, ExportRequest request) {
|
public PlainTextExport(File output, ExportRequest request) {
|
||||||
super(output, request);
|
super(output, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FileWriter output(File file) throws IOException {
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
return new FileWriter(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BigInteger chunkSize() {
|
protected BigInteger chunkSize() {
|
||||||
// These variables control how the output will be formatted
|
// These variables control how the output will be formatted
|
||||||
|
@ -49,7 +44,7 @@ public final class PlainTextExport extends FileExport<FileWriter> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void transfer(FileWriter output, BigInteger factor, IProgressMonitor monitor)
|
protected void transfer(OutputStream output, BigInteger factor, IProgressMonitor monitor)
|
||||||
throws IOException, DebugException {
|
throws IOException, DebugException {
|
||||||
// These variables control how the output will be formatted
|
// These variables control how the output will be formatted
|
||||||
// The output data is split by chunks of 1 addressable unit size.
|
// The output data is split by chunks of 1 addressable unit size.
|
||||||
|
@ -69,17 +64,18 @@ public final class PlainTextExport extends FileExport<FileWriter> {
|
||||||
buf.append(" "); //$NON-NLS-1$
|
buf.append(" "); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
BigInteger from = transferAddress.add(dataCellSize.multiply(BigInteger.valueOf(i)));
|
BigInteger from = transferAddress.add(dataCellSize.multiply(BigInteger.valueOf(i)));
|
||||||
byte[] bytes = read.from(from);
|
MemoryByte[] bytes = read.from(from, dataCellSize.longValue());
|
||||||
for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
|
for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
|
||||||
String bString = BigInteger.valueOf(0xFF & bytes[byteIndex]).toString(16);
|
//FIXME: check MemoryByte#isReadable
|
||||||
|
String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
|
||||||
if (bString.length() == 1) {
|
if (bString.length() == 1) {
|
||||||
buf.append("0"); //$NON-NLS-1$
|
buf.append("0"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
buf.append(bString);
|
buf.append(bString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.write(buf.toString().toUpperCase());
|
output.write(buf.toString().toUpperCase().getBytes());
|
||||||
output.write("\n"); //$NON-NLS-1$
|
output.write("\n".getBytes()); //$NON-NLS-1$
|
||||||
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) {
|
||||||
|
|
|
@ -15,33 +15,29 @@
|
||||||
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
|
|
||||||
public final class RAWBinaryExport extends FileExport<FileOutputStream> {
|
public final class RAWBinaryExport extends FileExport {
|
||||||
|
|
||||||
public RAWBinaryExport(File input, ExportRequest request) {
|
public RAWBinaryExport(File input, ExportRequest request) {
|
||||||
super(input, request);
|
super(input, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FileOutputStream output(File file) throws IOException {
|
|
||||||
return new FileOutputStream(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BigInteger chunkSize() {
|
protected BigInteger chunkSize() {
|
||||||
return BigInteger.valueOf(1024);
|
return BigInteger.valueOf(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void transfer(FileOutputStream output, BigInteger factor, IProgressMonitor monitor)
|
protected void transfer(OutputStream output, BigInteger factor, IProgressMonitor monitor)
|
||||||
throws IOException, DebugException {
|
throws IOException, DebugException {
|
||||||
BigInteger transferAddress = start;
|
BigInteger transferAddress = start;
|
||||||
BigInteger jobCount = BigInteger.ZERO;
|
BigInteger jobCount = BigInteger.ZERO;
|
||||||
|
@ -52,8 +48,11 @@ public final class RAWBinaryExport extends FileExport<FileOutputStream> {
|
||||||
length = end.subtract(transferAddress);
|
length = end.subtract(transferAddress);
|
||||||
}
|
}
|
||||||
monitor.subTask(transferring(length, transferAddress));
|
monitor.subTask(transferring(length, transferAddress));
|
||||||
byte[] byteValues = read.from(transferAddress);
|
MemoryByte[] byteValues = read.from(transferAddress, length.longValue() / addressable.longValue());
|
||||||
output.write(byteValues);
|
for (MemoryByte memoryByte : byteValues) {
|
||||||
|
//FIXME: check MemoryByte#isReadable
|
||||||
|
output.write(memoryByte.getValue());
|
||||||
|
}
|
||||||
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) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.debug.internal.core.memory.transport;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ReadMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.IReadMemory;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
import org.eclipse.debug.core.model.IMemoryBlockExtension;
|
import org.eclipse.debug.core.model.IMemoryBlockExtension;
|
||||||
import org.eclipse.debug.core.model.MemoryByte;
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
|
@ -24,24 +24,17 @@ import org.eclipse.debug.core.model.MemoryByte;
|
||||||
* Reads memory from the given {@link IMemoryBlockExtension}
|
* Reads memory from the given {@link IMemoryBlockExtension}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class ReadMemoryBlock implements ReadMemory {
|
public final class ReadMemoryBlock implements IReadMemory {
|
||||||
|
|
||||||
private final IMemoryBlockExtension memory;
|
private final IMemoryBlockExtension memory;
|
||||||
private final long unit;
|
|
||||||
|
|
||||||
public ReadMemoryBlock(IMemoryBlockExtension memory) {
|
public ReadMemoryBlock(IMemoryBlockExtension memory) {
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
this.unit = BigInteger.valueOf(1).longValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] from(BigInteger offset) throws DebugException {
|
public MemoryByte[] from(BigInteger offset, long units) throws DebugException {
|
||||||
MemoryByte[] received = memory.getBytesFromOffset(offset, unit);
|
return memory.getBytesFromOffset(offset, units);
|
||||||
byte[] bytes = new byte[received.length];
|
|
||||||
for (int i = 0; i < received.length; i++) {
|
|
||||||
bytes[i] = received[i].getValue();
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,26 +15,22 @@
|
||||||
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
package org.eclipse.cdt.debug.internal.core.memory.transport;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
import org.eclipse.cdt.debug.core.memory.transport.FileExport;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.MemoryByte;
|
||||||
|
|
||||||
public final class SRecordExport extends FileExport<FileWriter> {
|
public final class SRecordExport extends FileExport {
|
||||||
|
|
||||||
public SRecordExport(File input, ExportRequest request) {
|
public SRecordExport(File input, ExportRequest request) {
|
||||||
super(input, request);
|
super(input, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FileWriter output(File file) throws IOException {
|
|
||||||
return new FileWriter(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BigInteger chunkSize() {
|
protected BigInteger chunkSize() {
|
||||||
// FIXME 4 byte default
|
// FIXME 4 byte default
|
||||||
|
@ -42,18 +38,19 @@ public final class SRecordExport extends FileExport<FileWriter> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void transfer(FileWriter output, BigInteger factor, IProgressMonitor monitor)
|
protected void transfer(OutputStream output, BigInteger factor, IProgressMonitor monitor)
|
||||||
throws IOException, DebugException {
|
throws IOException, DebugException {
|
||||||
final BigInteger DATA_PER_RECORD = chunkSize();
|
final BigInteger DATA_PER_RECORD = chunkSize();
|
||||||
|
final BigInteger DATA_PER_TRANSFER = BigInteger.valueOf(4096).multiply(DATA_PER_RECORD);
|
||||||
BigInteger jobCount = BigInteger.ZERO;
|
BigInteger jobCount = BigInteger.ZERO;
|
||||||
BigInteger transferAddress = start;
|
BigInteger transferAddress = start;
|
||||||
while (transferAddress.compareTo(end) < 0 && !monitor.isCanceled()) {
|
while (transferAddress.compareTo(end) < 0 && !monitor.isCanceled()) {
|
||||||
BigInteger length = DATA_PER_RECORD;
|
BigInteger length = DATA_PER_TRANSFER;
|
||||||
if (end.subtract(transferAddress).compareTo(length) < 0) {
|
if (end.subtract(transferAddress).compareTo(length) < 0) {
|
||||||
length = end.subtract(transferAddress);
|
length = end.subtract(transferAddress);
|
||||||
}
|
}
|
||||||
monitor.subTask(transferring(length, transferAddress));
|
monitor.subTask(transferring(length, transferAddress));
|
||||||
byte[] bytes = read.from(transferAddress);
|
MemoryByte[] bytes = read.from(transferAddress, length.longValue() / addressable.longValue());
|
||||||
BigInteger sRecordAddress = transferAddress;
|
BigInteger sRecordAddress = transferAddress;
|
||||||
BigInteger sRecordEndAddress = transferAddress.add(length);
|
BigInteger sRecordEndAddress = transferAddress.add(length);
|
||||||
while (sRecordAddress.compareTo(sRecordEndAddress) < 0 && !monitor.isCanceled()) {
|
while (sRecordAddress.compareTo(sRecordEndAddress) < 0 && !monitor.isCanceled()) {
|
||||||
|
@ -61,7 +58,7 @@ public final class SRecordExport extends FileExport<FileWriter> {
|
||||||
if (sRecordEndAddress.subtract(sRecordAddress).compareTo(sRecordDataLength) < 0) {
|
if (sRecordEndAddress.subtract(sRecordAddress).compareTo(sRecordDataLength) < 0) {
|
||||||
sRecordDataLength = end.subtract(sRecordAddress);
|
sRecordDataLength = end.subtract(sRecordAddress);
|
||||||
}
|
}
|
||||||
output.write("S3"); // FIXME 4 byte address //$NON-NLS-1$
|
output.write("S3".getBytes()); // FIXME 4 byte address //$NON-NLS-1$
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
BigInteger sRecordLength = BigInteger.valueOf(4); // address size
|
BigInteger sRecordLength = BigInteger.valueOf(4); // address size
|
||||||
|
@ -80,7 +77,8 @@ public final class SRecordExport extends FileExport<FileWriter> {
|
||||||
final int byteOffset = sRecordAddress.subtract(transferAddress).intValue();
|
final int byteOffset = sRecordAddress.subtract(transferAddress).intValue();
|
||||||
final int byteLength = byteOffset + sRecordDataLength.intValue();
|
final int byteLength = byteOffset + sRecordDataLength.intValue();
|
||||||
for (int byteIndex = byteOffset; byteIndex < byteLength; byteIndex++) {
|
for (int byteIndex = byteOffset; byteIndex < byteLength; byteIndex++) {
|
||||||
String bString = BigInteger.valueOf(0xFF & bytes[byteIndex]).toString(16);
|
//FIXME: check MemoryByte#isReadable
|
||||||
|
String bString = BigInteger.valueOf(0xFF & bytes[byteIndex].getValue()).toString(16);
|
||||||
if (bString.length() == 1) {
|
if (bString.length() == 1) {
|
||||||
buf.append("0"); //$NON-NLS-1$
|
buf.append("0"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -101,8 +99,8 @@ public final class SRecordExport extends FileExport<FileWriter> {
|
||||||
buf.append("0"); //$NON-NLS-1$
|
buf.append("0"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
buf.append(bString);
|
buf.append(bString);
|
||||||
output.write(buf.toString().toUpperCase());
|
output.write(buf.toString().toUpperCase().getBytes());
|
||||||
output.write("\n"); //$NON-NLS-1$
|
output.write("\n".getBytes()); //$NON-NLS-1$
|
||||||
sRecordAddress = sRecordAddress.add(sRecordDataLength);
|
sRecordAddress = sRecordAddress.add(sRecordDataLength);
|
||||||
jobCount = jobCount.add(BigInteger.ONE);
|
jobCount = jobCount.add(BigInteger.ONE);
|
||||||
if (jobCount.compareTo(factor) == 0) {
|
if (jobCount.compareTo(factor) == 0) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.io.File;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ReadMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.IReadMemory;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.PlainTextExport;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.PlainTextExport;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
||||||
|
@ -451,7 +451,7 @@ public class PlainTextExporter implements IMemoryExporter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportMemory() {
|
public void exportMemory() {
|
||||||
ReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
IReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
||||||
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
||||||
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
||||||
PlainTextExport memoryExport = new PlainTextExport(fOutputFile, request);
|
PlainTextExport memoryExport = new PlainTextExport(fOutputFile, request);
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.io.File;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ReadMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.IReadMemory;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.RAWBinaryExport;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.RAWBinaryExport;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
||||||
|
@ -454,7 +454,7 @@ public class RAWBinaryExporter implements IMemoryExporter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportMemory() {
|
public void exportMemory() {
|
||||||
ReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
IReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
||||||
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
||||||
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
||||||
RAWBinaryExport memoryExport = new RAWBinaryExport(fOutputFile, request);
|
RAWBinaryExport memoryExport = new RAWBinaryExport(fOutputFile, request);
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.io.File;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
import org.eclipse.cdt.debug.core.memory.transport.ExportRequest;
|
||||||
import org.eclipse.cdt.debug.core.memory.transport.ReadMemory;
|
import org.eclipse.cdt.debug.core.memory.transport.IReadMemory;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.ReadMemoryBlock;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.SRecordExport;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.SRecordExport;
|
||||||
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
import org.eclipse.cdt.debug.internal.core.memory.transport.TransportJob;
|
||||||
|
@ -489,7 +489,7 @@ public class SRecordExporter implements IMemoryExporter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportMemory() {
|
public void exportMemory() {
|
||||||
ReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
IReadMemory read = new ReadMemoryBlock((IMemoryBlockExtension) fMemoryBlock);
|
||||||
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
BigInteger addressable = new AddressableSize((IMemoryBlockExtension) fMemoryBlock).get();
|
||||||
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
ExportRequest request = new ExportRequest(fStartAddress, fEndAddress, addressable, read);
|
||||||
SRecordExport memoryExport = new SRecordExport(fOutputFile, request);
|
SRecordExport memoryExport = new SRecordExport(fOutputFile, request);
|
||||||
|
|
Loading…
Add table
Reference in a new issue